Click here to Skip to main content
14,269,202 members
Rate this:
Please Sign up or sign in to vote.
Hi,

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 asp.net using C# code.

Thanks in advance.


Regards,
Aditya.
Posted
Updated 24-Nov-13 21:18pm
v2
Rate this:
Please Sign up or sign in to vote.

Solution 1

   
Comments
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.
Rate this:
Please Sign up or sign in to vote.

Solution 2

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()
       {
           alert('calling');
// to call a server function.. ( create a button with style as dispay:none  , and call that button click event  )
       }

   </script>
   

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

  Print Answers RSS
Top Experts
Last 24hrsThis month



CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100