Problem calling radalert from code-behind

6 posts, 0 answers
  1. Ferdinand
    Ferdinand avatar
    56 posts
    Member since:
    Jun 2008

    Posted 09 Sep 2009 Link to this post

    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
  2. Svetlina Anati
    Admin
    Svetlina Anati avatar
    2795 posts

    Posted 09 Sep 2009 Link to this post

    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.
  3. Ferdinand
    Ferdinand avatar
    56 posts
    Member since:
    Jun 2008

    Posted 09 Sep 2009 Link to this post

    Hi svetlina,
    thanks for the fast reply. The code is working fine.

    Ferdinand
  4. Ferdinand
    Ferdinand avatar
    56 posts
    Member since:
    Jun 2008

    Posted 09 Sep 2009 Link to this post

    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
  5. Svetlina Anati
    Admin
    Svetlina Anati avatar
    2795 posts

    Posted 09 Sep 2009 Link to this post

    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.
  6. Ferdinand
    Ferdinand avatar
    56 posts
    Member since:
    Jun 2008

    Posted 09 Sep 2009 Link to this post

    Thanks,
    this time it works...
Back to Top