Javascript code

  • Thread starter Thread starter Shaul Feldman
  • Start date Start date
S

Shaul Feldman

Hello,
I'm trying to figure out what's the most convinient way to write JavaScript
code in ASP.Net, espacially when JavaScript code has to recieve certain
values from server side. In classic ASP it was quiet simple, here I get in
trouble. Thank you for your help.

S. Feldman
 
With ASP.NET javascript generate serverside is very simple.
You can use RegisterClientScriptBlock or RegisterStartupScript method.
For Javascript fired by html element you can make this element runat server
and write code similar this :
htmlInput.Attributes["OnChange"] = "doSomething();"

Brun
 
Thank you for help,
the problem is when you write
htmlInput.Attributes["OnChange"] = "doSomething();"
the "doSomething();" is a string, and I can't debug it on the server side,
only accept client-side errors.
Is there any efficient way to write that "doSomething();" than a simple
string object, in order to debug?
Or I should first write it in regular html file and only after that turn
into String on server-side?
Also would you be so kind to stay on the differences between those two
methods you wrote, "RegisterClientScriptBlock" and "RegisterStartupScript" -
what are differences?
Thanks a lot again :)

--
With the best wishes,
Shaul Feldman


Bruno Sirianni said:
With ASP.NET javascript generate serverside is very simple.
You can use RegisterClientScriptBlock or RegisterStartupScript method.
For Javascript fired by html element you can make this element runat server
and write code similar this :
htmlInput.Attributes["OnChange"] = "doSomething();"

Brun


Shaul Feldman said:
Hello,
I'm trying to figure out what's the most convinient way to write JavaScript
code in ASP.Net, espacially when JavaScript code has to recieve certain
values from server side. In classic ASP it was quiet simple, here I get in
trouble. Thank you for your help.

S. Feldman
 
On serverside you cannot debug clientside script.
Make script in Html and then turn it into String on server can be a
solution. This string on server can be changed dinamically for accept
parameters.

RegisterClientScriptBlock MSDN remark:
The client-side script is emitted just after the opening tag of the Page
object's <form runat= server> element. The script block is emitted as the
object that renders the output is defined, so you must include both tags of
the <script> element.

RegisterStartupScript MSDN remark:

Similar to the RegisterClientScriptBlock method, this method emits the
script just before the closing tag of the Page object's <form runat= server>
element. The script block is emitted as the object that renders the page is
defined, so you must include both tags of the <script> element.

Brun

Shaul Feldman said:
Thank you for help,
the problem is when you write
htmlInput.Attributes["OnChange"] = "doSomething();"
the "doSomething();" is a string, and I can't debug it on the server side,
only accept client-side errors.
Is there any efficient way to write that "doSomething();" than a simple
string object, in order to debug?
Or I should first write it in regular html file and only after that turn
into String on server-side?
Also would you be so kind to stay on the differences between those two
methods you wrote, "RegisterClientScriptBlock" and "RegisterStartupScript" -
what are differences?
Thanks a lot again :)

--
With the best wishes,
Shaul Feldman


Bruno Sirianni said:
With ASP.NET javascript generate serverside is very simple.
You can use RegisterClientScriptBlock or RegisterStartupScript method.
For Javascript fired by html element you can make this element runat server
and write code similar this :
htmlInput.Attributes["OnChange"] = "doSomething();"

Brun


Shaul Feldman said:
Hello,
I'm trying to figure out what's the most convinient way to write JavaScript
code in ASP.Net, espacially when JavaScript code has to recieve certain
values from server side. In classic ASP it was quiet simple, here I
get
 
Back
Top