This is a migrated thread and some comments may be shown as answers.

Problem calling radalert from code-behind

5 Answers 289 Views
Window
This is a migrated thread and some comments may be shown as answers.
Ferdinand
Top achievements
Rank 1
Ferdinand asked on 09 Sep 2009, 07:46 AM
Hello,
I am trying call a radalert window from code-behind. For this I followed the instructions here.
I registered a RadWindowManager in my Master page and called the radalert from the client page's code-behind.
Here's the code for both of them:
Master:
<form id="form1" runat="server"
    <telerik:RadScriptManager ID="MasterScriptManager" runat="server" EnablePageMethods="True" 
        EnableScriptGlobalization="True" EnableTheming="True"
        <Services> 
            <asp:ServiceReference Path="~/Ws/KanioService.asmx"></asp:ServiceReference> 
        </Services> 
    </telerik:RadScriptManager> 
    <telerik:RadAjaxManager ID="ramMaster" runat="server"
        <AjaxSettings> 
            <telerik:AjaxSetting AjaxControlID="ktbMaster"
            </telerik:AjaxSetting> 
        </AjaxSettings> 
    </telerik:RadAjaxManager> 
    <telerik:RadFormDecorator ID="masterFormDecorator" runat="server" DecoratedControls="All" /> 
    <telerik:RadWindowManager ID="rwmKanioMaster" runat="server"
    </telerik:RadWindowManager> 
    <div id="container"
 
... 
   

client's code-behind:
clientScript = "radalert('" + Resources.GlobalTranslation.selectFirst + "');"
RadScriptManager.RegisterStartupScript(thisthis.GetType(), "openWindow", clientScript, true); 

Now Firebug gives me the following error:
l is undefined

5 Answers, 1 is accepted

Sort by
0
Svetlina Anati
Telerik team
answered on 09 Sep 2009, 08:07 AM

Hi Ferdinand,

The controls in the RadControls for ASP.NET AJAX suite are built upon the MS AJAX framework and the framework itself creates its controls (including RadWindowManager) in the Sys.Application.add_init() method.

Here is how the client events are fired in the page life cycle:

window.onload -> Sys.Application.init -> Sys.Application.load

You can see that the client object representation of MS AJAX controls are created just as the last code on the page in the Sys.Application.init event, which is raised after the window.onload event.

That is why when you call your code in window.onload by registering the client script, the RadWindowManager will still not be created on the page and you will get an error. To avoid this problem, you can either execute your code with a small timeout, or use the Sys.Application.add_load method.

This being said I suggest to modify your code in the following manner:

code-behind:

clientScript = "Sys.Application.add_load(function(){radalert('" + Resources.GlobalTranslation.selectFirst + "');});";    
RadScriptManager.RegisterStartupScript(thisthis.GetType(), "openWindow", clientScript, true);    
 


Greetings,

Svetlina
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Ferdinand
Top achievements
Rank 1
answered on 09 Sep 2009, 08:13 AM
Hi svetlina,
thanks for the fast reply. The code is working fine.

Ferdinand
0
Ferdinand
Top achievements
Rank 1
answered on 09 Sep 2009, 08:24 AM
Hi again,
I think I was to fast telling you everything worked fine ;)
By changing the code as suggested I am registering the radalert with Sys.Application.add_load which means the radalert always appears on callbacks made on the page.
Is there any way to avoid that?

Ferdinand
0
Svetlina Anati
Telerik team
answered on 09 Sep 2009, 08:41 AM
Hello Ferdinand,

The behavior you describe comes from teh fact that the handler is added and not removed. What I suggest is to do the following:

  1. Declare the function which calls the radalert..
  2. Execute it in the Sys.Application.add_load method.
  3. In the code of the function which calls the radalert use the Sys.Application.remove_load syntax to remove the handler.

More infomration about executing scripts from the server is available in the following blogpost:

http://blogs.telerik.com/blogs/posts/09-05-05/executing_javascript_function_from_server-side_code.aspx

Regards,
Svetlina
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Ferdinand
Top achievements
Rank 1
answered on 09 Sep 2009, 11:37 AM
Thanks,
this time it works...
Tags
Window
Asked by
Ferdinand
Top achievements
Rank 1
Answers by
Svetlina Anati
Telerik team
Ferdinand
Top achievements
Rank 1
Share this question
or