Hi there,
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... ;)
So, to have an alert pop up in the client, you'll have to send some JavaScript. You can add something to the attributes collection of a button. For example, you can add code that will be attached to the onclick attribute for an input element. Let's look at an example. Suppose you have a simple button on an ASPX page:
Code:
<asp:Button id="Button1" runat="server" Text="Click Me"></asp:Button>
When clicked, the following code will run at the
server:
Code:
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:
Code:
Button1.Attributes.Add("onclick",
"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:
Code:
<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.
In this example I used the confirm method to ask for confirmation, but you can also use the JavaScript
alert method if you want just a dialog with an OK button.
Does this help?
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.