Click here to Skip to main content
15,881,173 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
Hi everyone. I have asp.net page and confirmation message when I click on button. But when i click yes to this my page refreshing( do postback). How can I make confirmation message without resfreshing my page?
Asp.net C# Framework 2.0 JS
ASP.NET
<asp:Button ID="SaveBtn" runat="server"  Text="Save" CssClass="btngo" OnClientClick="javascript:return confirm('Do you want to Save?');" OnClick="SaveBtn_Click" />
Posted

When you hit a button that has as server side event attached to it (in your case SaveBtn_Click) the page will do a postback automatically...
The confirmation has nothing to do with it, the only connection is that the client side even handler called BEFORE the server side one, and can stop postback if it returns false...
So, if you choose No/Cancel in your confirmation dialog, it will return false and the process will not continue - no postback.
However if you choose Yes/OK the confirmation dialog will return true and the server side event handler will be called - postback!
 
Share this answer
 
Comments
Andrey Golubtsov 11-Mar-15 11:07am    
And its no way to make it without refreshing?
You can make an ajax call to the server side method when the user click yes in the js confirm box. Refer: AJAX for Beginners (Part 3) - Calling Server Side Methods and Consuming Web Services from JavaScript in an ASP.NET website[^] so that there will be no page refresh.
 
Share this answer
 
v2
Comments
Andrey Golubtsov 11-Mar-15 11:27am    
Thanks)
The simplest way is to put your controls inside an asp:UpdatePanel. That will submit the form asynchronously with no page refresh and you don't need to do any coding.
 
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