tags:

views:

89

answers:

5

how do we call client script from asp.net server side script?

+3  A: 

Try this: How to: Add Client Script Dynamically to ASP.NET Web Pages from MSDN

Daniel Dyson
+2  A: 

You can try code below:

ScriptManager.RegisterStartupScript(this, this.GetType(), Guid.NewGuid().ToString("N"), "alert('ok');", true);
Tony
A: 

insert the button and double click it..add this property. runat="server"

in ur code behind file right this code

Page.ClientScript.RegisterStartupScript(this.GetType(), "clientscript", "document.getElementById('Button').style.visibility = 'visible';" ,true);

Ayyappan.Anbalagan
A: 

u can do by adding button and any event on that button for as ur requirement. suppose u want to delete the text box after insertiion of string.then u 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 ur textbox is empty automatically

picnic4u
+1  A: 

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.
Mac