Published articles on other web sites*

Published articles on other web sites*

Call JavaScript from an ASP.NET AJAX Update Panel in Content Page Load

While calling a JavaScript function from a Content Page Load method, you can use the ClientScript.RegisterStartupScript method. However the same does not work if the content page is wrapped inside an ASP.NET AJAX Update Panel. To call a Javascript function at page load in an Update Panel scenario, you need to instead use the ScriptManager.RegisterStartupScript method that registers a startup script block with the ScriptManager control and adds the script block to the page.

Here’s an example. In the Page_Load of the content page, write the following code:


This is the code that registers a script block

ScriptManager.RegisterStartupScript(this, this.GetType(), 'call', str.ToString(), false);

Using the RegisterStartupScript(Page, Type, String, String, Boolean) overload registers a startup script block every time that an asynchronous postback occurs.

Update: On the same note, check out a nice article by Krishna Using .NET’s Register Script methods with jQuery’s $(document).ready()

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...