CODEDIGEST
Home Articles CodeDigest Tutorials FAQs
Skip Navigation LinksHome » CodeDigest » Dynamically Adding JavaScript in ASP.Net AJAX   You are not logged in.
Search
 

Sponsored Links
 

Technologies
 

CodeDigest Navigation
 

Technology News
No News Feeds available at this time.
 

Community News
No News Feeds available at this time.
 
Dynamically Adding JavaScript in ASP.Net AJAX. Call Javascript function from UpdatePanel on AJAX Postback.
Dynamically Adding JavaScript in ASP.Net AJAX. Call Javascript function from UpdatePanel on AJAX Postback.
Submitted By Satheesh Babu B
On 12/14/2008 6:09:33 AM
Tags: ASP.Net AJAX,CodeDigest,JavaScript  

Dynamically Adding JavaScript in ASP.Net AJAX

To add a Javascript function programmatically from codebehind we use the new ClientScriptManager class in asp.net 2.0. The same methods in ClientScriptManager class will not inject scripts when we try to add it from an Asynchronous postback in ASP.Net AJAX.

 

The ScriptManager class is packed with all the client side script injection methods in ASP.Net AJAX.

 

To insert a start up script from a AJAX postback,

ScriptManager.RegisterStartupScript(btnSubmit, Page.GetType(), "alert", "alert('test')", true);

 

The boolean parameter in the last will dictate whether to add script tags.

 

To inject a confirm script from a AJAX postback,

ScriptManager.RegisterOnSubmitStatement(btnSubmit, Page.GetType(), "confirm", "return confirm('Are you sure');");

 

To register a Client Script block,

ScriptManager.RegisterClientScriptBlock(btnSubmit, Page.GetType(), "alert", "alert('test')", true);

 

The boolean parameter in the last will dictate whether to add script tags.

 

Do you have a working code that can be used by anyone? Submit it here. It may help someone in the community!!

Recent Codes
  • View All Codes..