Click here to Skip to main content
15,741,203 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)

I have a scenario Where after clicking the button i need to retrieve the data from the database and based on the value i need to alert an confirmation message box. If yes is clicked in the confirmation message box then need to execute the remaining set of code else exit from the Button click event.

Can any one give an idea how to do in using C# code.

Thanks in advance.

Updated 24-Nov-13 21:18pm

Share this answer
aditya kiran maroju 25-Nov-13 3:24am    
But here the confirmation message is raised from the client click event where i cannot retrieve any value from the database because the click event is raised before entering the click event
OriginalGriff 25-Nov-13 3:59am    
You can't do that: the website page cycle doesn't work like that.
It isn't like a WinForms app when you application is servicing a single user - you have a cycle of operation which means processing is required on both sides of the internet communications medium.

Server code cannot directly interact with the user: it sends data which is interpreted by the client browser which interacts with the user and then sends any data back to the server.
You can't just open a MessageBox and wait for an "OK" or "Cancel" button click, because you can't directly display anything to the client.

What you have to do is respond to the "DELETE" click, request the alert at the user, then respond to the "OK" click with the actual delete operation as a set of separate post backs.
aditya kiran maroju 25-Nov-13 4:18am    
Thanks for prompt reply griff. is there any other way that i can perform this task with only a single click event.
OriginalGriff 25-Nov-13 4:52am    
The only other way to do it is by doing the alert direct from the javascript instead of going to the server for the first click, and only telling teh server if the user clicks the OK button.
hi Try this code...

if any doubt , leave a comment..

protected void btnsubmit_Click(object sender, EventArgs e)
            // do some code and get the value
            bool value = true;
            if (value)
                string script = " <script type=\"text/javascript\"> var val = confirm('ur message ???');  if(val){calfun();}  </script> ";
                //  this.Page.ClientScript.RegisterStartupScript(typeof(Page), "alert", script);
                //ScriptManager.RegisterStartupScript(this,typeof(Page), "alert", message);
                ScriptManager.RegisterStartupScript(this, typeof(Page), "alert", script, false);

<script type="text/javascript">
       function calfun()
// to call a server function.. ( create a button with style as dispay:none  , and call that button click event  )

Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900