tags:

views:

351

answers:

2

Hi,

I'm sure you have had this one before so if you could point me to something similar....

I have a server side creation of a RadAlert window using the usual Sys.Application.remove_load and add_load procedure however the alert keeps popping up as it seems to be caching when the user hits the back button after it has been activated. I have tried to put a onclick event on a button to clear the function using remove_load before it moves to the next page however it still doesn't seem to clear it.

Its used in validation so if a user inputs failed validation it pops up. If they then go and enter correct validation it then moves onto the next page. If they then use back button this is where it pops up again. Any ideas?

Server side:

private void Page_Load(object sender, System.EventArgs e) 
{
   if (!IsPostBack) 
   {
      btnSearch.Attributes.Add("onclick", "Sys.Application.remove_load(f);"); 
   }
}

private void btnSearch_Click(object sender, System.EventArgs e) 
{
   string radalertscript = "(function(){var f = function(){radalert('Welcome to RadWindow Prometheus!',     330,     210);   Sys.Application.remove_load(f);};Sys.Application.add_load(f);})()";

   RadAjaxManager1.ResponseScripts.Add(radalertscript);
}

Ive also tried using

   RadAjaxManager1.ResponseScripts.Clear();

before it moves on to the next page on the postback event

A: 

I don't think the problem is with the radalert() function - You will get the same behavior if you use the normal browser alert() as well. The Sys.Application.Load event is raised each time the page is loaded in the browser - including when you use the back button to open it again. If the code that adds the radalert() is also on the page, it will run as well and the alert will be displayed during Load.

lingvomir
+1  A: 

What lingvomir says is correct. What I would suggest as a solution is to ajaxify that Search Button. e.g.

 <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
    <AjaxSettings>
        <telerik:AjaxSetting AjaxControlID="RadAjaxManager1">
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="Button1" />
            </UpdatedControls>
        </telerik:AjaxSetting>
    </AjaxSettings>
</telerik:RadAjaxManager>
<telerik:RadWindowManager ID="RadWindowManager1" runat="server">
</telerik:RadWindowManager>
<asp:Button ID="Button1" runat="server" Text="show radalert" OnClick="Button1_Click" /><br />

and in codebehind:

 protected void Button1_Click(object sender, EventArgs e)
{
    string radalertscript = "radalert('Welcome to RadWindow Prometheus!',330,210);";
    RadAjaxManager1.ResponseScripts.Add(radalertscript);
}
GeorgiTunev