I am trying to display a "Yes / No" messagebox from codebehind in C#. I want to call an "AddRecord" procedure if the user clicks "Yes", and do nothing if the user clicks "No".
Ideally, I want to use the code below, but from codebehind:
OnClientClick = "return confirm('Are you sure you want to delete?');"
I search on SO and google, but was not able to find anything helpful.
on your Add Record button, just do the following:
<asp:button ID="AddRecordbutton" runat="server" Text="Add Record"
onclick="AddRecordButton_Click" onclientclick="return confirm('add record?');" />
In your code behind, just put the add record code in your AddRecordButton_Click event handler. It will only be called if they click Yes on the popup.
Alternatively, you could have your codebehind assign the onclientclick code when the button is initially rendered.
For example:
protected void Page_Load(object sender, EventArgs e) {
AddRecordButton.OnClientClick = @"return confirm('Add Record?');";
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With