Click here to Skip to main content
15,888,263 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

I want to call Javascript confirm dialog box at runtime on my button click. I can call it onclientclick but, my problem is i want to call it after some processing on button click in code behind.

Also, I have used UpdatePanel in my code design and this I want on my custom User Control. One more thing I am also using Master Page. Please check my below sample code.

C#
protected void btnSkipRecord_Click(object sender, EventArgs e)
   {
       if(reader.read())
{
string scriptString = @"<SCRIPT language='javascript'> return confirm('" + msg + "')</SCRIPT>";
this.Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "StartUp", scriptString, false);
}


I have debugged the code and its executing without error but not displaying confirm message. Is there any solution then please guide me.
Posted
Updated 8-Jul-10 21:03pm
v2

1 solution

Hi,

If you are using your user control in your update panel, This code won't work. Yes that is correct this code won't give you any error also. You need to check that whether your button click event is fired via update panel with "ScriptManager.GetCurrent(Me.Page).IsInAsyncPostBack". If it is then you have to register javascript with the use of "ScriptManager.RegisterClientScriptBlock" in place of "Page.ClientScript.RegisterClientScriptBlock"

Thanks
 
Share this answer
 
Comments
neal123 9-Jul-10 2:15am    
Hi I have follow below way,

if (readEmail.Read())
{

System.Web.UI.ScriptManager Manager = System.Web.UI.ScriptManager.GetCurrent(this.Page);
if (Manager.IsInAsyncPostBack)
{
System.Web.UI.ScriptManager.RegisterClientScriptBlock(this, this.GetType(), Guid.NewGuid().ToString(), "alert('hello');" + Page.ClientScript.GetPostBackEventReference(this, "") + ";", true);
}
}
But not getting any alert.
purav topiwala 9-Jul-10 3:53am    
Reason for my vote of 3
this will solve ur problem.
Mehul M Thakkar 12-Jul-10 0:38am    
I am not getting about "your problem". Write comment properly. About the answer then it is absolutely working fine at every end. If it is not working, it depends where you have written in your code.

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