Click here to Skip to main content
15,896,207 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,
I have a gridview and on Page Indexing I need to show an confirm box alert with Ok and Cancel. I have an update button in the page and gridview has dropdown values. When user changes the dropdown values in gridview and try to move to next page without clicking update button, then I need to show an alert like "Make sure you have updated the changes before navigation". I have tried lot of JS and nothing helped.

I am using this peice of code in my page indexing. The alert pops up but not the confirm box with Ok and Cancel.

C#
string script = "alert('Make sure you have updated the page before navigation!')";
    ScriptManager.RegisterStartupScript(Page, Page.GetType(), "Alert", script, true);


Really appreciate any help on this.
Posted
Updated 4-Mar-14 17:30pm
v3

Hey Bro,

You need to use "Confirm Box" of JavaScript that have O.k and Cancel button by default, you can't update alert box in JavaScript so instead of alert use confirm.

You can check this Article as well:

http://www.c-sharpcorner.com/uploadfile/syedshakeer/how-to-show-alert-and-confirmation-message-box-in-Asp-Net/[^]
 
Share this answer
 
v2
Comments
vignesht50 4-Mar-14 5:22am    
This can be done for buttons. But how can I tie this up to page indexing in gridview.
C#
ScriptManager.RegisterStartupScript(this, typeof(string), "ConfirmMessage", "if(confirm('Make sure you have updated the page before navigation!')){alert('OK');}else{alert('cancel');}",true);
 
Share this answer
 
Comments
vignesht50 4-Mar-14 5:27am    
When I click on paging the alert box comes as expected. But the problem is whenever I click in OK or Cancel again a dialog box comes up for those. If I click Ok a dialog box appears again with Ok. Also when I click paging the page navigates to next page before I click OK.

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