I want to show alert Message when user tries to navigate between pages in Gridview.
If user navigates to next page I need to give an alert like "Make sure you updated the page before you move" and a pop up should display. If yes is clicked it should go to another page or if cancel is clicked it has to stay in the same page
Loading

Joginder BangerRank #360 · 7K reputationPosted Jan 22, 2015, 5:56 AM EST
protected void grid_pageindexchanging(object sender, GridViewPageEventArgs e)
{
string script = "";
ClientScript.RegisterClientScriptBlock(this.GetType(), "Alert", script);
if(script(
{
// do stuff here.....
}
}
kris26 reputationPosted Jan 22, 2015, 11:00 PM EST
Joginder BangerRank #360 · 7K reputationPosted Jan 22, 2015, 11:15 PM EST
{
if(e.NewPageIndex<1)
{string script = "";
ClientScript.RegisterClientScriptBlock(this.GetType(), "Alert", script);
}
}
Khargesh RajputRank #616 · 3.9K reputationPosted Jan 22, 2015, 11:44 PM EST
<script type = "text/javascript"> function Confirm() {
var confirm_value = document.createElement("INPUT");
confirm_value.type = "hidden";
confirm_value.name = "confirm_value";
if (confirm("Make sure you updated the page before you move?")) {
confirm_value.value = "Yes";
} else {
confirm_value.value = "No";
}
document.forms[0].appendChild(confirm_value);
}
script>
protected void grid_pageindexchanging(object sender, GridViewPageEventArgs e)
{
string confirmValue = Request.Form["confirm_value"];
if (confirmValue == "Yes")
{
fncBindGrid();
}
else
{
grid.PageIndex = e.NewPageIndex;
fncBindGrid();
}
}