Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

We have a requirement where we need to call a web service and display the value returned from service in a confirmation box and if the user clicks OK need to update the data base and if he clicks CANCEL need to show the original screen with out executing the update logic.

Thanks in Advance !!

Regards,
Hari
Posted

You can use this way. I'm just giving you hint, don't know your exact scenario.

Javascript:
JavaScript
<script type="text/javascript">
    function CallConfirmBox(passedvalue) {        
        if (confirm("Confirm Proceed Further With " + passedvalue + "?")) {
            //OK – Do your stuff or call any callback method here..
            alert("You pressed OK!");
            return true; //important
        } else {
            //CANCEL – Do your stuff or call any callback method here..
            alert("You pressed Cancel!");
            return false; //important
        }
    }
</script>


.aspx Markup:
<asp:Button ID="btnCall" runat="server" Text="Click Me!" OnClick="btnCall_Click" />


Call it from code-behind: C#
C#
protected void btnCall_Click(object sender, EventArgs e)
{
   //service code here and pass your retrieved value from here..
   string myServiceVal = "some value here..";
   ScriptManager.RegisterStartupScript(this, this.GetType(), "CallConfirmBox",  "CallConfirmBox("'+ myServiceVal +'");", true);
   //your rest update code..
} 


Reference: http://www.aspneto.com/how-to-show-confirm-message-box-from-code-behind-asp-net.html[^]
 
Share this answer
 
v4
Comments
machcha 13-Mar-15 11:01am    
Hi,

Thanks for the reply.Tried with the soluton provided by the code after the script manager is getting execute along with that.I need to get a retrun value and based on hte return value I want the rest of my code get executed.If user clicks OK some value should be returned based on that value my code from code behind should get executed.

Thanks,
Hari
Modi Mayank 13-Mar-15 23:47pm    
1. If you want to go with my above example, you can put one hiddenfield in your .aspx page and update it's value in CallConfirmBox JavaScript function using jQuery or JavaScript according to user selection. After that check your hiddenfield value server side below the script manager and according to that value decide whether to update data or not.

2. Use AJAX model popup extender OR you can also try any 3rd party tools to achieve this.
machcha 14-Mar-15 12:05pm    
Hi,

We are not supposed to used AJAX controls.I tried by using hidden fields and updating that value in JavaScript and executing the code but during debug I could see that the ScriptMangager is executed and immediately the rest of code executes then we are getting the confirm box which will not meet the purpose.

Thanks,
Hari
You need to do the following:

1)Call the web service and if it returns data from the server successfully then show the value.

$.ajax({//your service parameters}).then(function(){ //show the box })

2) After that write the code to handle the condition of updating or not-updating your database(which may need another service call).
 
Share this answer
 
There are a few different methods shown here[^]

It'll need a fairly decent grasp of asp.net framework though.
 
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