How do we call client script from asp.net server side script?
-
Please provide more details. Currently your question doesn't make sense.Darin Dimitrov– Darin Dimitrov2010-05-24 08:41:04 +00:00Commented May 24, 2010 at 8:41
-
quesion incomplete..what u exactly askingAyyappan Anbalagan– Ayyappan Anbalagan2010-05-24 09:00:28 +00:00Commented May 24, 2010 at 9:00
6 Answers
Here are two of these methods :
Page.ClientScript.RegisterStartupScript(Type, String key, String script)
Page.ClientScript.RegisterClientScriptBlock(Type, String key, String script)
The "Type " & "Key" pair distinguish between the different registered script. So you can't register two script having both same type & key pair. The above two methods do the same thing with a basic difference that specify where to
use these functions.
1.RegisterClientScriptBlock() method add the script before the controls are renderd in the page. So the scripts we are registered can't acess the controls inside the page.
e.g : var name = document.getElementById('txtName'); //will not work as excepted.
2.RegisterStartupScript() method add the script before the end of body tag after all the controls are rendered in the browser. So the registered script can acess the controls inside the page .
e.g : var name = document.getElementById('txtName'); //will work fine.
Comments
You can call following line on any of your server side event.
Page.ClientScript.RegisterStartupScript(this.GetType(), "Script", "alert('Test Event');", true);
1 Comment
You can do this by adding button and on any event on that button for as your requirement.
Suppose you want to delete the text box after insertion of a string.
Then you simply double click on that button itself and go to that code behind file and simply put code like:
txtbox1.text = null;
after each click event your textbox is empty automatically