I got "ok":
Catching "okay" is pretty simple. When you press "ok" in a confirm box the server side button click event is automatically fired. Let's see a very simple example.
|private void InitializeComponent()
this.BtnSave.Click += new System.EventHandler(this.BtnSave_Click);
this.Load += new System.EventHandler(this.Page_Load);
In the example above I just added the "onclick" attribute to the BtnSave Button control. The server side button click event will look something like this:
|private void BtnSave_Click(object sender, System.EventArgs e)
Response.Write("I am Server Side button click and I am fired");
Now, when you click the "ok" button from the confirm window you will see that server side button event is fired and Response.Write puts the message on the screen. The bad thing is that when you press "cancel" from the confirm box nothing happens. The reason is that "cancel" is only handled on the client side. Let's see how we can access the "cancel" button click.
AJAX COMES TO THE RESCUE:
Server Side Update and Add Method:
I am not going to implement the whole Add and Update Method but I will just define the methods and leave the implementation for the readers.
public string UpdateMethod()
// Do your update thing here
return "Record Updated";
public string AddMethod()
// Do your Adding in the database here
return "Record Added";
If you have been following my previous articles about AJAX than this is very simple code for you. If NOT than shame on you and visit the links below.
I hope you liked the article, happy coding!