Reputation: 349
I wants to display an OK/CANCEL message box. I have written like this.
if (MessageBox.Show("Are you sure you wants to Save the details ? ", "Validate", MessageBoxButtons.OKCancel) == DialogResult.OK)
{
// do something if "OK "
}
it works locally well.. but on IIS shows an error " Showing a modal dialog box or form when the application is not running in UserInteractive mode is not a valid operation. Specify the ServiceNotification or DefaultDesktopOnly style to display a notification from a service application." please help.
Upvotes: 1
Views: 2530
Reputation: 15425
To get the effect I believe you are wanting, you'll want to use the Javascript confirm()
function. It is typically used like this:
<asp:Button runat="server" OnClientClick="return confirm('Are you sure you want to save the details?')" id="btnSubmit" OnClick="btnSubmit_Click" />
This would, upon clicking the button, display a confirmation box that would stop the server OnClick event from firing if the user clicks No, Cancel, etc.
OnClientClick
will render as an onclick
event on the <input>
tag. The rest is determined by the browser's handling of Javascript. See What's the effect of adding 'return false' to a click event listener? for more details on what the return value of the code in OnClick
(OnClientClick
) does.
Here's an example of the return values of confirm() using Chrome. For the first execution I had clicked Cancel.
Upvotes: 3