You must Sign In to post a response.
  • Category: .NET

    ClientScript.RegisterStartupScript Not working after adding Update Panel

    HI Guys,

    I have report grid in which if i click a particular row, it will open another page of document view. I use the ClientScript.RegisterStartupScript(this.GetType(), "script", sb.ToString()) in the code behind to open this page. (sb.ToString()is the script written in code behind to open the another page) Everything was working good.

    Now i added the update panel to the page (added in master page). Now the ClientScript.RegisterStartupScript is not working nor throwing any exception error. Will the update panel will affect the ClientScript.RegisterStartupScript() ? Help me to resolve this.

    Rajabharathi R
  • #765548

    When you are using Update Panel don't use ClientScript.RegisterStartupScript, instead of this use ScriptManager.RegisterStartupScript, this will help you to resolve your issue.


    ScriptManager.RegisterStartupScript(UpdatePanelID,UpdatePanelID.GetType(), "close", "alert('hello');", true);

    Give respect to your work, Instead of trying to impress your boss.

    Blog :

  • #765552
    When you use Update Panel dont use ClientScript.RegisterStartupScript
    Use ScriptManager.RegisterStartupScript
    When you use update panel then you can not call javascript like this ..
    Try Following Code,

    string CloseWindow;
    CloseWindow = "alert('Hello World')";
    ScriptManager.RegisterStartupScript(UpdatePanelID,UpdatePanelID.GetType(), "CloseWindow", CloseWindow, true);

    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

  • #765748
    You have to use System.Web.UI.ScriptManager.RegisterClientScriptBlock or ScriptManager.RegisterStartupScript instead of Page.ClientScript.RegisterStartupScript because you are registering the script when the page is postback to the server using UpdatePanel. UpdatePanel uses Asynchronous callback to the server when performing postback using AJAX therefore you need to use either of the above ways of registering the scripts.
    Miss. Jain
    Microsoft Certified Technology Specialist in .Net

Sign In to post your comments