ScriptManager.RegisterClientScriptBlock not working fom masterpage code behind file

  The have the jquery powered signup and signin div on master page. when the user clicks the link  the modal popup comes uo and the user signup. i kept my functionality on the master.cs.
Everything works fine in master.cs except calling a javascript fuction from master.cs.
    I have included Script manager on the master page, i am using update panel on the master page.master.cs. The fuction  ScriptManager.RegisterClientScriptBlock does not fires the javascript function

Below is the code from Masterpage.Master

<head runat="server">
   <script type="text/javascript">
        function TestJs()

            alert("Testing javscript fire");

         function closeDialog(id) {
            $('#' + id).dialog("close");


    <form id="form1" class="niceform" runat="server">
       <asp:ScriptManager ID="ScriptManager1" runat="server">
    <div id="webpage-container">
        <div id="modaldialog-container">
            <div id="signup-container">
                <asp:UpdatePanel ID="Upsignup" UpdateMode="Conditional" ChildrenAsTriggers="true" runat="server">

                    //signup contents
                        <asp:AsyncPostBackTrigger ControlID="btnSubmit" EventName="Click" />
                        <asp:AsyncPostBackTrigger ControlID="btnReset" EventName="Click" />
            </div> <!--end signup container-->
        <!--end modaldialog-container-->
        <asp:ContentPlaceHolder id="bodycontents" runat="server">
  </div> <!--end webpage-container-->

Below is the code from Masterpage.Master.cs

protected void btnSubmit_Click(object sender, EventArgs e)

        if (Page.IsValid)


            //Close the Dialog Box

            ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "UniqueScript", "TestJS();", true)



Open in new window

Who is Participating?
StephanLead Software EngineerCommented:
I think the problem lies with the loading event, it doesn't know when to fire it. Maybe use an onload function in order to trigger the function onload... in jQuery it goes like this:

$(document).load(function(){ TestJS(); });

Here is for default javascript:
RajeshbalaAuthor Commented:
no this doesn't work for me..I am calling this javascript function from code-behind only if it successfully submitted condition..

    ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "UniqueScript", "TestJS();", true)

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

StephanLead Software EngineerCommented:
Did you try Page instead of ScriptManager?

like so:

Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "UniqueScript", "TestJS();", true)
RajeshbalaAuthor Commented:
thanks for your reply stephan..But this doesn't work either..I am wondering is that possible to call javascript from master.cs instead from content page (aspx.cs)?
RajeshbalaAuthor Commented:
Thanks Stephan...I read the article...i fixed the issue..the problem in my case is the button is wrapped inside the update panel..i came to know that if a button is wrapped inside the update panel then the
Page.ClientScript.RegisterClientScriptBlock() won't execute....
  Instead i used the worked
 string script = string.Format(@"closeDialog('{0}')", dialogId);
        ScriptManager.RegisterStartupScript(Page, this.GetType(), "UniqueID", script, true);

RajeshbalaAuthor Commented:
Fixed the issue
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.