Click here to Skip to main content
15,881,898 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi ,

Iam trying to display an alert box from the codebehind, all of my controls are inside my update panel, when the button click event occurs it should display an alert box
code behind:
SQL
ScriptManager.RegisterStartupScript(this.MyUpdatePanel,this.GetType(),Guid.NewGuid().ToString(),"alert('hello')",true);
            ScriptManager.RegisterStartupScript(this, typeof(Page), UniqueID, "alert('Data successfully insert into database');", true);
           ScriptManager.RegisterStartupScript(this, this.GetType(), Guid.NewGuid().ToString(), "alert('hello');", true);


i have used all these types of code if i put this in a code without update panel its working fine but if i use it in an code using update panel the alert box is not displaying, pls help me out got struck with this for more than a day
Posted

C#
Response.Write("<script>alert('Hello!! I am Nirav Prabtani')</script>");
 
Share this answer
 
Attache JavaScript function / code to your button.
C#
btnMyButton.Attributes.Add("onclick", "javascript:altert('Hello')");
 
Share this answer
 
Comments
ashok_89 6-Jun-13 3:51am    
No this is also not working in my code
virang_21 6-Jun-13 23:13pm    
If your button is inside update panel did you add <Triggers> section to your update panel ?

<Triggers>
<asp:PostBackTrigger ControlID="btnMyButton" />
</Triggers>

Also set UpdateMode="Conditional" for your Update Panel
Hi,
try this.

ScriptManager.RegisterStartupScript(btnMyButton, this.GetType(), "test", "alert('Hello');", true);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900