views:

261

answers:

3

Hi, I have a javascript alert popup on my page. Problem I am having with it is that instead of waiting for the user to actually click the OK button, it simply does a redirect, something it ought to do AFTER the OK button has been clicked. Can anyone please help me tweak my code so as to get this working as it ought to please?

function f()
{

    ar ape =radalert('<div align=""center"" style=""font-weight: bold;""> OPEN BOX HERE</div>', 123, 200);
if(ape)window.location.href = "/Default.aspx";
Sys.Application.remove_load(f);
}

Sys.Application.add_load(f);
+2  A: 

You're not using a JavaScript alert (in the sense of the built-in function), it looks like you're using something called radalert (from Telerik). That means it can't behave like a JavaScript alert, which brings script processing to a screeching halt while it's on-screen.

I know nothing about Telerik, but most of these alert replacements offer a callback you can pass that gets triggered when the alert is cleared. That's where you want your window.location.href = ... code.

Usually this looks something like this:

function blah() {

    niftyAlertThingy("Here's my message", {
        onOK: function() {
            window.location.href = "/Default.aspx";
            // etc.
        }
    });
}

That blah function returns immediately, with the alert still on the page; then the alert code calls your callback when the user clicks OK.

I'm sure the Telerik radalert has something similar...

T.J. Crowder
Telerik does have something similar, but it's driven by the MS AJAX event subscription model, no callbacks. CMS covers it in his answer http://stackoverflow.com/questions/1928804/javascript-alert-with-confirmation/1928896#1928896
Crescent Fresh
Big +1 to CMS for finding the blasted docs. @Crescent Fresh: Surely that's a callback, though! ;-)
T.J. Crowder
@T.J.: you know what I mean ;)
Crescent Fresh
@CF: I didn't, but that's okay. :-)
T.J. Crowder
A: 

I would think your code would need more explanation and possibly your code behind too (just the relevant code on how you handle "OK" Click). My experience with telerik is not good. I would suggest you to try jQuery UI. It gives you better control on how you can handle events and where.

Example( From here)

$(function(){

    $("#dialog").dialog({
    autoOpen: false,
    modal:true,
    buttons : {
     "Yes" : function() {              
      $(this).dialog("close");
      eval($("#<%= hdnBtnPostback.ClientID %>").val());
     },
     "No" : function() {
      $(this).dialog("close");
     },
     "Maybe": function() {
      $(this).dialog("close");
      //what should we do when "Maybe" is clicked?
     }        
    }
    });
});
ram
+2  A: 

You can use the add_close method to attach a callback funtion to know when the alert is closed:

var win = radalert('foo');
win.add_close(function () {
  alert('bar'); // This will be executed when the radalert is closed.
});

More info:

CMS
Nice research on the return value of `radalert`.
Crescent Fresh
+1 big time, in the time I gave it, I couldn't find the blasted reference docs.
T.J. Crowder