alert message box in update panel
-
string msg = "You cannot select more seats."; System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.Append("<script type='text/javascript'>"); sb.Append("window.onload=function(){"); sb.Append("alert('"); sb.Append(msg); sb.Append("')};"); sb.Append("</script>"); ScriptManager.RegisterClientScriptBlock(this,typeof(Page), "alert", sb.ToString(),false); i tried to display the dialog box on click event of a button in update panel......but its leading to a runtime error that i'm unable to debug....please if anyone can have a look at the code and tell me if there is an error....also tell me any other necessary property of scriptmanager or update panel that i need to set ....i'm using this thing for the first time....so not much familiar with the procedure.
-
string msg = "You cannot select more seats."; System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.Append("<script type='text/javascript'>"); sb.Append("window.onload=function(){"); sb.Append("alert('"); sb.Append(msg); sb.Append("')};"); sb.Append("</script>"); ScriptManager.RegisterClientScriptBlock(this,typeof(Page), "alert", sb.ToString(),false); i tried to display the dialog box on click event of a button in update panel......but its leading to a runtime error that i'm unable to debug....please if anyone can have a look at the code and tell me if there is an error....also tell me any other necessary property of scriptmanager or update panel that i need to set ....i'm using this thing for the first time....so not much familiar with the procedure.
So if you want to show the message on button click then why you assigned the function to
window.onload
event,I just tried your code and put itPage_Load
and it was showing the alert message... :) So if you want to run it on button click the use the code belowstring msg = "You cannot select more seats.";
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append("<script type='text/javascript'>");
sb.Append("function ShowAlert(){");
sb.Append("alert('");
sb.Append(msg);
sb.Append("'); return false;};");
sb.Append("</script>");
ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "alert", sb.ToString(), false);and button should be as
<asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="javascript:return ShowAlert();" />
let me know if face any issue.
Cheers!! Brij Check my latest Article :Exploring ASP.NET Validators
-
So if you want to show the message on button click then why you assigned the function to
window.onload
event,I just tried your code and put itPage_Load
and it was showing the alert message... :) So if you want to run it on button click the use the code belowstring msg = "You cannot select more seats.";
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append("<script type='text/javascript'>");
sb.Append("function ShowAlert(){");
sb.Append("alert('");
sb.Append(msg);
sb.Append("'); return false;};");
sb.Append("</script>");
ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "alert", sb.ToString(), false);and button should be as
<asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="javascript:return ShowAlert();" />
let me know if face any issue.
Cheers!! Brij Check my latest Article :Exploring ASP.NET Validators
Hi Brij.... Thanks for your reply... actually i'm counting the number of buttons clicked by user with the value contained in a session variable....and when the no of clicks cross that value then i wanna display the alert message....if i'll put it on "onclientclick" property then how can i get the condition checked ??