ATLAS Issue: RegisterStartupScript and RegisterClientScriptBlock do not work in atlas:UpdatePanel?

Damir Dobric Posts

Next talks:

 

    

Follow me on Twitter: #ddobric



 

 

Archives

To understand this ATLAS issue imagine there is a page which has an asp:button control and corresponding handler, which is called when the button is clicked. The requirement is to show the alert window, when the button ‘cmd’ is clicked.  To do that the handler function ‘cmd_Click’ register the client script block by calling of RegisterStartupScript (the same issue can be noticed by using of RegisterClientScriptBlock too). This pattern is mostly when som pop-up windows have to be opened.

 

 

<asp:Button ID="cmd " runat="server" OnClick="cmd_Click" />

 

 

protected void cmd_Click(object sender, EventArgs e)

{

       string script = @"<script language=""javascript"">

                    alert(‘hello’)</script>";

 

       if (IsPostBack){

       this.ClientScript.RegisterStartupScript(this.GetType(),

       "ShowPopup", script);     

       }

  }

}

 

If the same ASP.NET code is inserted in the atlas:UpdatePannel control the alert-window will not appear.

 

<atlas:UpdatePanel ID="UpdatePanel1" runat="server" Mode="Always">

 <ContentTemplate>

  <asp:Button ID="cmd " runat="server" OnClick="cmd_Click" />

 </ContentTemplate>

</atlas:UpdatePanel>

 

The generated script code should usually appear at the buttom of the HTMP page:


<script language="javascript">

alert("2");

</script>

 

However the generated script looks different when update pannel is used:
 

<script language="javascript">

<![CDATA[alert("2")]]>

</script>

 

This is a reason, why the script is not executed. Currently the only way (I know) to workaround this problem is to avoid using of the button-control with UpdatePanel.


Posted Jul 20 2006, 12:00 PM by Damir Dobric
Filed under:

Comments

beam wrote re: ATLAS Issue: RegisterStartupScript and RegisterClientScriptBlock do not work in atlas:UpdatePanel?
on 09-14-2006 19:15
try (as simple as this):

protected void cmd_Click(object sender, EventArgs e)
   {
       if (IsPostBack)
       {

           this.ClientScript.RegisterStartupScript(this.GetType(),
               
               "ShowPopup", "alert('hello')", true);
       }
   }
Damir Dobric wrote re: ATLAS Issue: RegisterStartupScript and RegisterClientScriptBlock do not work in atlas:UpdatePanel?
on 09-15-2006 8:53
Thanks for the comment beam.
I compared the stream returned from the server in both cases. It is almost identical.
However, both examples work with the build 2.0.50727.0 of Microsoft.Web.Atlas.dll.

Damir
Damir Dobric Posts wrote RegisterStartupScript and RegisterClientScriptBlock can work with UpdatePanel?!
on 02-12-2007 14:47

Imagine you have a control which registers some trivial script, which has to be executed during loading

and wrote re: ATLAS Issue: RegisterStartupScript and RegisterClientScriptBlock do not work in atlas:UpdatePanel?
on 09-07-2007 9:47

ScriptManager.RegisterStartupScript(Page, this.GetType(), "aKey", "alert(1);", true); worked for me

Anil Desai wrote re: ATLAS Issue: RegisterStartupScript and RegisterClientScriptBlock do not work in atlas:UpdatePanel?
on 06-03-2009 15:22

ScriptManager.RegisterStartupScript(Page, this.GetType(), "titOne", "methodTest();", true); worked for me

Dushyant wrote re: ATLAS Issue: RegisterStartupScript and RegisterClientScriptBlock do not work in atlas:UpdatePanel?
on 11-04-2011 22:37

Comment by Anil Desai worked for me too

I tried this without the call of function i.e. I wrote the complete script in a string and tried but didn't worked. A function call is working perfectly

Thanx Anil

developers.de is a .Net Community Blog powered by daenet GmbH.