Confirmation Message Box in Code Behind Asp.Net [modified]
-
Hai all, I want to display confirmation message box in Asp.net code behind (C#). When I save the record i am doing some validations , in the validation function i need to display confirmation message with "yes" or "no" , if "yes" the save process should be done and if "no" save process should not be proceed . I have used Page.ClientScript.RegisterStartupScript() ,but it is not working. I have also tried btnSave.Attributes.Add("onclick", "return confirm()"); but the confirmation message is opened before save . I need only at the time of validation . Please Help me. Thank u
modified on Friday, December 17, 2010 12:42 AM
-
Hai all, I want to display confirmation message box in Asp.net code behind (C#). When I save the record i am doing some validations , in the validation function i need to display confirmation message with "yes" or "no" , if "yes" the save process should be done and if "no" save process should not be proceed . I have used Page.ClientScript.RegisterStartupScript() ,but it is not working. I have also tried btnSave.Attributes.Add("onclick", "return confirm()"); but the confirmation message is opened before save . I need only at the time of validation . Please Help me. Thank u
modified on Friday, December 17, 2010 12:42 AM
<asp:Button ID="btnSave" runat="server" Text="Save" OnClick="btnSave_Click" OnClientClick="return confirm('Do you really want to save?');" />
Just use this in your button and I am sure it will work definitely.
Regards, Hiren.
My Recent Article: - Way to know which control have raised PostBack
My Recent Tip/Trick: - Remove HTML Tag, get plain Text -
<asp:Button ID="btnSave" runat="server" Text="Save" OnClick="btnSave_Click" OnClientClick="return confirm('Do you really want to save?');" />
Just use this in your button and I am sure it will work definitely.
Regards, Hiren.
My Recent Article: - Way to know which control have raised PostBack
My Recent Tip/Trick: - Remove HTML Tag, get plain TextThanks for the reply I no need to call the function in onClientClick() , that will work fine . I need to call the script function only at the server side validation because the confirmation message should work based on the server side validation. Thank you
-
Thanks for the reply I no need to call the function in onClientClick() , that will work fine . I need to call the script function only at the server side validation because the confirmation message should work based on the server side validation. Thank you
Can you please show us
Page.ClientScript.RegisterStartupScript()
, what you've written inside ?Regards, Hiren.
My Recent Article: - Way to know which control have raised PostBack
My Recent Tip/Trick: - Remove HTML Tag, get plain Text -
Can you please show us
Page.ClientScript.RegisterStartupScript()
, what you've written inside ?Regards, Hiren.
My Recent Article: - Way to know which control have raised PostBack
My Recent Tip/Trick: - Remove HTML Tag, get plain TextThis is my coding protected void btnSave_Click(object sender, Infragistics.WebUI.WebDataInput.ButtonEventArgs e) { try { if (!fnValidate()) return; else { save(); } } catch (Exception ex) { throw(ex); } } bool fnValidate() { Page.ClientScript.RegisterStartupScript(this.GetType(), "ClientScript", ""); } Client side function function confirmUpdate() { var agree = vbConfirm(Are you sure do you want to continue ?'); if (agree == true) { return true; } else { return false; } }</x-turndown>
-
This is my coding protected void btnSave_Click(object sender, Infragistics.WebUI.WebDataInput.ButtonEventArgs e) { try { if (!fnValidate()) return; else { save(); } } catch (Exception ex) { throw(ex); } } bool fnValidate() { Page.ClientScript.RegisterStartupScript(this.GetType(), "ClientScript", ""); } Client side function function confirmUpdate() { var agree = vbConfirm(Are you sure do you want to continue ?'); if (agree == true) { return true; } else { return false; } }</x-turndown>
priyagee wrote:
Page.ClientScript.RegisterStartupScript(this.GetType(), "ClientScript", "confirmUpdate();</b></blockquote> See that, you haven't closed with <code></script></code>. <div class="signature">Regards, Hiren. <div class="callout align-center" style="margin:1px"><b><font color="red">My Recent Article:</font></b> - <a href="http://www.codeproject.com/KB/aspnet/Postback\_raising\_control.aspx">Way to know which control have raised PostBack</a><br /><b><font color="red">My Recent Tip/Trick:</font></b> - <a href="http://www.codeproject.com/Tips/136704/Remove-all-the-HTML-tags-and-display-a-plain-text-.aspx">Remove HTML Tag, get plain Text</a></div></div></x-turndown>
-
This is my coding protected void btnSave_Click(object sender, Infragistics.WebUI.WebDataInput.ButtonEventArgs e) { try { if (!fnValidate()) return; else { save(); } } catch (Exception ex) { throw(ex); } } bool fnValidate() { Page.ClientScript.RegisterStartupScript(this.GetType(), "ClientScript", ""); } Client side function function confirmUpdate() { var agree = vbConfirm(Are you sure do you want to continue ?'); if (agree == true) { return true; } else { return false; } }</x-turndown>