How to stop a page from rendering .cs code when clicking cancel button in javascript confirmation window?
I have a button click event and in some IF state I ask the user to confirm. Now, when the user clicks the OK button, I need to bind the new data in the grid. but if the user presses the cancel button, he should not update the grid with new data.
Question: clicking the cancel button in the JavaScript confirmation window, how can I stop the following code from executing, or how can I just return / cancel JavaScript?
Can anyone help me with this? Thanks in advance.
Markup
<asp:Button ID="btnCopy" runat="server" Text="Copy" Enabled="false" OnClick="btnCopy_Click" ValidationGroup="Copy" />
the code
public void btnCopy_Click(object sender, EventArgs e) { if (Convert.ToInt32(hidId.Value) > 0) { string scriptString = "<script language='JavaScript'> "; scriptString += "if (confirm('Are you sure to proceed?') == false) {return} "; scriptString += "</script>"; Page.RegisterStartupScript("Confirm", scriptString); BindDataGrid(); } }
source share