0

I have a button in a GridView, and when it is clicked it triggers the

protected void GridView_RowCommand(object sender, GridViewCommandEventArgs e)

event. In there I have some logic and at the end I am registering some javascript that generates a pop up. The issue I am having is that for the confirm pop up when it comes up. It shows a blank screen on the background and when I click cancel it shows it back again, otherwise it navigates to another page... But while the box is up the background is white.

I need to make it so that it shows like the "Alert" pop up that still shows the website in the background. Please note I can only make this work with these pop ups as they are used throughout the website ("not confirm ones"). This is the first confirm box I have had to add but there are many Alerts on other pages. So would not like to change them as it will be too much work (150+ pages website).

Thank you

user710502
  • 11,181
  • 29
  • 106
  • 161

1 Answers1

1

It looks like the page isn't getting a chance to render before the alert box shows up. Hook up the code that displays the JavaScript alert to something like the body.onload event; this will wait for the page to finish its initial load before displaying the alert.

            Page.ClientScript.RegisterClientScriptBlock(
                this.GetType(), 
                "key",
                @"
function Redirect() {
  location.href = 'shoppingCart.aspx';
}

function showAlert() {
  if (confirm('***Message truncated***.') == true){
    Redirect();
  };
}

// If you're using JQuery, you could do something like this, otherwise you
// would need to add the function call to the HTML body tag's onload attribute.
// There are other alternatives, see:
// http://stackoverflow.com/questions/1235985/attach-a-body-onload-event-with-js
$(document).ready(function() {
  showAlert();
});

", true);
Ivan Karajas
  • 1,081
  • 8
  • 14