You'll have to think a bit about the ASP.NET architecture before you realize the cause of your problem. ASP.NET runs on the server
, while you view the output / pages in your browser at the client
. If you were able to pop up a dialog from ASP.NET code, it would pop up at the server. And guess who has to close those zillion dialogs again... ;)
<asp:Button id="Button1" runat="server" Text="Click Me"></asp:Button>
When clicked, the following code will run at the server
private void Button1_Click(object sender, System.EventArgs e)
// Do server side stuff here.
As I explained before, you can't pop up an alert here, because this code runs at the server. To fix that, you need to add the following code to the Page_Load event:
"return(confirm('Are you sure you want to submit?'));");
When the page loads, the button gets an extra attribute called onclick in the client side code. When you run the page and click the button, you'll see a dialog box asking for confirmation. If you click OK, the page will submit, otherwise it stays where it is. If you look at the source in the browser (in the client), this is what you'll see:
<input type="submit" name="Button1"
value="Click Me" id="Button1"
onclick="return(confirm('Are you sure you want to submit?'));" />
The code for the onclick has been attached to te button at the browser, providing for all this magic.
method if you want just a dialog with an OK button.
Does this help?
Everyone is unique, except for me.