RADAjax Manager does not load JS files in dynamically loaded user control

66 posts, 0 answers
  1. zaphod94
    zaphod94 avatar
    10 posts
    Member since:
    Jun 2007

    Posted 12 Nov 2007 Link to this post

    Looks like this is a bug in RADAjaxManager and I havent been able to find a suitable workaround

    1. I have a page with a button and a asp panel control.
    2. The page has been Ajaxified using the RADPrometheus Ajax Manager.
    3. Click of button triggers dynamic load of a user control into the panel
    4. The user control includes webusercontrol.js file via Script Manager Proxy.
    5. User control has a button and a text box
    6. Button click has been wired to call a setTest() js function defined in webusercontrol.js
    7. When the page renders, I click the button to dynamically load the user control into the panel.
    8. Clicking the button on the user control to set the text results in "Object required" error. What is happening is that the setText() function defined in the included script file is not visible.

    //// Default.aspx
    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="TelerikAjaxTest._Default" EnableEventValidation="false" %>

    <%@ Register Assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        Namespace="System.Web.UI" TagPrefix="asp" %>

    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>Telerik Prometheus RADAjaxManager Text</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server"
            EnablePartialRendering="true"
            EnablePageMethods="true"
            LoadScriptsBeforeUI="true">
            <Scripts></Scripts>
        </asp:ScriptManager>
        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
            <AjaxSettings>
                <telerik:AjaxSetting AjaxControlID="btnLoadControl">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="pnlContent" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
            </AjaxSettings>
           
        </telerik:RadAjaxManager>
        <div>
            <asp:Button ID="btnLoadControl" runat="server" Text="Load Control" />
        </div>
        <div>
            <asp:Panel ID="pnlContent" runat="server"></asp:Panel>
        </div>
        </form>
    </body>
    </html>

    ////// Default.aspx.cs
    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;

    namespace TelerikAjaxTest {
        public partial class _Default:System.Web.UI.Page {
            protected void Page_Load(object sender, EventArgs e) {
                this.btnLoadControl.Click += new EventHandler(btnLoadControl_Click);
            }

            void btnLoadControl_Click(object sender, EventArgs e) {
                this.pnlContent.Controls.Clear();
                UserControl uc;
                uc = Page.LoadControl("WebUserControl1.ascx") as UserControl;

                if (uc != null) {
                    this.pnlContent.Controls.Add(uc);
                }

            }
        }
    }

    //// WebUserControl1.ascx
    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="WebUserControl1.ascx.cs" Inherits="TelerikAjaxTest.WebUserControl1" %>
    <%@ Register Assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        Namespace="System.Web.UI" TagPrefix="asp" %>
    <asp:ScriptManagerProxy ID="ScriptManagerProxy1" runat="server">
        <Scripts>
            <asp:ScriptReference Path="WebUserControl.js" NotifyScriptLoaded="true" />
        </Scripts>
    </asp:ScriptManagerProxy>
    <div>
        Web User Control with Script Manager Proxy
        This controls is loaded dynamically via the click of the button on
        the main page
    </div>
    <div>
        <button id="btnAddText" runat="server" onclick="setText">Set Text</button>
    </div>
    <div>
        <asp:TextBox ID="txtName" runat="server"></asp:TextBox>
    </div>
    <script type="text/javascript">
        var txtNameId=<%= txtName.ClientID %>;
       
        alert('WebUserControl1.ascx');
    </script>

    ////// WebUserControl.js
    // WebUserControl.js

    function setText(){
        var oTxt=$get(txtNameId);
        if((oTxt!=null)&&(typeof(oTxt)!='undefined')){
            oTxt.value=oTxt.value+'Some Text';
        }
    }

    // Notify the AJAX framework that this script has completed loading.
    // Making this the last line in the file ensures that this is executed
    // last
    if(typeof(Sys) !== "undefined")Sys.Application.notifyScriptLoaded();





    Any feed back appreciated

    thanks
    zaphod
  2. rwozniak
    rwozniak avatar
    47 posts
    Member since:
    Oct 2007

    Posted 14 Nov 2007 Link to this post

    I am very interested in seeing this work as well. I am currently using the Q2 2007 SP1 version of RadAjaxManager because EnablePageHeadUpdate does not yet appear to work in the Prometheus version.
  3. Plamen Peshev
    Admin
    Plamen Peshev avatar
    886 posts

    Posted 16 Nov 2007 Link to this post

    Hi rwozniak,


     

    Unfortunately this is a problem with our current implementation. I will forward your request to our development team. 

    One possible workaround is to set the Visible property of the UserControl to false. Please find attached a sample web application that demonstrates the needed approach.

    Let me know if you have other question and/or problems.

     




    Kind regards,
    Plamen
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  4. rwozniak
    rwozniak avatar
    47 posts
    Member since:
    Oct 2007

    Posted 16 Nov 2007 Link to this post

    This is unfortunately not an acceptable workaround, because your example assumes that I know at page load time what user control is going to be loaded into the panel.

    For example, an application may have a RadTree in a splitter pane on the left, and a Panel in the pane on the right. Depending on which tree node is clicked, a different user control will be dynamically loaded on the right. If there are 50 nodes on the left it would be highly impractical to load all 50 user controls (with Visible-false) on the right...just so that the resources will be available if its associated node is clicked.

    I would consider this current shortcoming to be a very, very serious one. After all, how can you have an EnablePageHeadUpdate property at all if it doesn't work when set to true?

    This is a showstopper for us. Without this functionality, we will be forced to stick w/ the non-Prometheus version of RadAjaxManager. This really concerns me, given the fact that it will eventually be unsupported. I'm also not sure of the implications of moving to the other Prometheus controls, but having to stay with a prior version of RadAjaxManager.

    Thanks,
    Ross
  5. Plamen Peshev
    Admin
    Plamen Peshev avatar
    886 posts

    Posted 20 Nov 2007 Link to this post

    Hi rwozniak,

    The second workaround is using RadScriptBlock to add an external javascript. I prepared another sample project (AJAXEnabledWebSite16.zip) for your reference and attached the files to this thread.

    I hope the current solution is applicable for you.


    Sincerely yours,
    Plamen
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  6. Michael Tissington
    Michael Tissington avatar
    63 posts
    Member since:
    Nov 2007

    Posted 24 Nov 2007 Link to this post

    I have this problem too, is there a solution yet ?
  7. Michael Tissington
    Michael Tissington avatar
    63 posts
    Member since:
    Nov 2007

    Posted 24 Nov 2007 Link to this post

    One more bit of information ...

    I am using RadCodeBlock with <% %> elements so I can not put it into a script file like your example ....

    The fact that the script is not getting loaded for subsequent loads of different usercontrols looks very much like an URGENT bug.
  8. Steve
    Admin
    Steve avatar
    10941 posts

    Posted 26 Nov 2007 Link to this post

    Hi Michael Tissington,

    The problem has already been addressed. I am attaching a trial version of the fix here for testing. Whoever needs dev build, please open a support ticket and we will provide you with one.

    Sorry for the inconvenience.

    Best wishes,
    Steve
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  9. Ramesh
    Ramesh avatar
    15 posts
    Member since:
    Nov 2007

    Posted 26 Nov 2007 Link to this post

    Steve,
    Can you please elaborate on which "problem" had been already fixed? The original RADAjax manager does not load JS files in dynamically loaded user control
    or
    Michael Tissington's specific issue with using RADCode  block

    If the original issue has been addressed I would like to get the hot fix too

    Please advise
    thanks
    ramesh
  10. Michael Tissington
    Michael Tissington avatar
    63 posts
    Member since:
    Nov 2007

    Posted 26 Nov 2007 Link to this post

    Steve, this does not appear to have fixed the problem .... :(
  11. UT_DEV
    UT_DEV avatar
    20 posts
    Member since:
    Sep 2007

    Posted 28 Nov 2007 Link to this post

    "The original RADAjax manager does not load JS files in dynamically loaded user control "

    But if you staticaly load controls in Page_Load method all works  perfect(but only for blocks stored in MS AjaxPanels)
  12. Steve
    Admin
    Steve avatar
    10941 posts

    Posted 29 Nov 2007 Link to this post

    Hi guys,

    Michael: I believe that I have pointed you to the problem in your case in your support ticket
    Ramesh: the original issue has not yet been fixed. It is logged in our bug tracking system and we will address it for subsequent release of the control (we will do our best to fix it for the official Prometheus release).

    Best wishes,
    Steve
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  13. Scott
    Scott avatar
    47 posts
    Member since:
    Mar 2006

    Posted 03 Dec 2007 Link to this post

    Glad to have seen this post.  I've spent (wasted) close to a day trying to figure out what's wrong and had to write a little test page to make sure my code was correct and came to the conclusion that it's a bug when user control is loaded dynamically...arrrgh!   But glad you guys are aware of it.
  14. Russell
    Russell avatar
    76 posts
    Member since:
    Sep 2006

    Posted 01 May 2008 Link to this post

    Any update on the status of dynamically loading script files from a user control?
  15. Yavor
    Admin
    Yavor avatar
    11 posts

    Posted 02 May 2008 Link to this post

    Hi Eric,

    The issue is still not resolved, bur our developers are aware of it and will address it soon.
    I hope it is not causing you much inconvenience in the meantime.

    All the best,
    Yavor
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  16. fabio selingrim
    fabio  selingrim avatar
    5 posts
    Member since:
    Jun 2008

    Posted 09 Feb 2009 Link to this post

    Any solutions for this problem ??
  17. SamJ
    SamJ avatar
    101 posts
    Member since:
    Jul 2008

    Posted 10 Feb 2009 Link to this post

    HI,

    Try registering your scripts through the ScriptManager.

    Regards,
    SamJ
  18. Albert Shenker
    Albert Shenker avatar
    567 posts
    Member since:
    Mar 2004

    Posted 17 Feb 2009 Link to this post

    I have a user control with some javascript that looks something like this...

    <telerik:RadCodeBlock ID="block1" runat="server">  
        <script language="javascript">  
              
            var Grid_CCC;  
            var Master_CCC;  
              
            function GridCreated_CCC(sender, eventArgs)  
            {  
                Grid_CCC = sender;  
                Master_CCC = Grid_CCC.get_masterTableView();  
            }  
              
    </telerik:RadCodeBlock> 

    I have a grid later in the control which has a clientsetting

    OnGridCreated

     

    ="GridCreated_CCC"

     

     

     

     

     


    When the user control is dynamically loaded after an ajax update, I get a javascript error telling me that GridCreated_CCC does not exist. I believe this is an example of the issue discussed in this thread. As you can see, I use a RadCodeBlock. I have also tried to use a RadScriptBlock, but the same error occurs. Is there any update as to a fix or workaround to this issue. It seems like it has been around a very long time.

    I am using the 2008 Q3 version 1314 controls.
  19. Sebastian
    Admin
    Sebastian avatar
    9934 posts

    Posted 18 Feb 2009 Link to this post

    Hi Albert,

    Have you tried to register the OnGridCreated client handler using the ScriptManager.RegisterStartupScript static method from within the dynamically loaded web user control? Thus the script should be registered and accessible on the page when you load the user control on ajax request.

    Another approach you can try is to move the RadCodeBlock on the main page.

    Kind regards,
    Sebastian
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  20. Albert Shenker
    Albert Shenker avatar
    567 posts
    Member since:
    Mar 2004

    Posted 18 Feb 2009 Link to this post

    As for B), I am using dynamically loaded user controls. I tried to add a script block around the user control in the dynamic loading process, but that didn't seem to make a difference.

    As for A), how do I use RegisterStartUpScript to register an event handler like Grid_Created? And where within the usercontrol event cycle? Can you please provide an example.
  21. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 19 Feb 2009 Link to this post

    Hi guys,

    Generally RadCodeBlock cannot execute JavaScript - you should use RadScriptBlock instead.

    Kind regards,
    Vlad
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  22. Albert Shenker
    Albert Shenker avatar
    567 posts
    Member since:
    Mar 2004

    Posted 19 Feb 2009 Link to this post

    I tried RadScriptBlock both inside the usercontrol and also to wrap around the usercontrol, and neither made a difference. There appears to be a suggested fix here (of using ScriptManager.Register....), but no one appears to be eager to provide an example.
  23. Sebastian
    Admin
    Sebastian avatar
    9934 posts

    Posted 19 Feb 2009 Link to this post

    Hi Albert,

    The signature of the method is specified in the MSDN article linked in my previous reply. You can use it in the same manner as you will register other javascript function in this case.

    Regards,
    Sebastian
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  24. Albert Shenker
    Albert Shenker avatar
    567 posts
    Member since:
    Mar 2004

    Posted 19 Feb 2009 Link to this post

    Thanks. I am aware of the syntax, I'm just not sure where to put it. I added the following in the Page_Load event handler of my user control:

    ScriptManager.RegisterStartupScript(Me, Me.GetType, "CCC", "GridCreated_CCC", True) 

    But it didn't seem to make a difference. I still get a 'GridCreated_CCC' is undefined javascript error when the usercontrol is loaded with an ajax update. I also tried it with the same syntax, but "False" for the include script tags attribute, and there was no difference.
  25. SamJ
    SamJ avatar
    101 posts
    Member since:
    Jul 2008

    Posted 20 Feb 2009 Link to this post

    Hi,

    I assume that this error is expected as you haven't really registered the 'GridCreated_CCC' method. Try the following:

    Dim script As String = "var Grid_CCC; var Master_CCC; " + "function GridCreated_CCC(sender, eventArgs) {  "  
       + " Grid_CCC = sender; Master_CCC = Grid_CCC.get_masterTableView(); }  " 
    ScriptManager.RegisterStartupScript(Page, GetType(Page), "script", script, True

    Tell me if it works.

    Thanks,
    SamJ


  26. Albert Shenker
    Albert Shenker avatar
    567 posts
    Member since:
    Mar 2004

    Posted 20 Feb 2009 Link to this post

    Thanks for the suggestion, SamJ, but that doesn't work either. And even if it did, it would certainly be an untennable solution. You can't go including all of your client-side code in code-behind. Anyways, given the length of this thread it appears that this bug has been known for a year and a half. I can't understand how it wouldn't be an urgent matter for telerik to fix it. Basically I am unable to use their Ajax Controls with dynamically-loaded User controls if the user control includes client-side scripting. Given that most of telerik's controls require client-side scripting, this puts me in a tremendous bind. It totally rules out user control load on demand scenarios, which are a primary performance improvement technique that telerik encourages. I'm not the first one to mention it in this thread, but this is becoming very frustrating.
  27. SamJ
    SamJ avatar
    101 posts
    Member since:
    Jul 2008

    Posted 20 Feb 2009 Link to this post

    Hi Albert,

    I agree with you.
    However until it is fixed, what we could do is to find alternative solutions for our cases. What I do if I were in your situation, I would move my client script into js files and just register the file through the ScriptManager.

    Regards,
    SamJ
  28. Albert Shenker
    Albert Shenker avatar
    567 posts
    Member since:
    Mar 2004

    Posted 20 Feb 2009 Link to this post

    I don't believe moving the script to a .js file is going to be an option. In each of my user controls, within the Codeblock there is a <style></style> section with the following. This is necessary to accomodate the updatepanel 100% height bug.

    <style type="text/css">  
    #<%= Me.GetMyAjaxManagerUpdatePanelId("pnlGrid") %> 
            {  
                margin:0;  
                height:100%;  
            }  
    </style> 

    GetMyAjaxManagerUpdatePanelId is a method which returns the client Id of the update panel.

    This style block cannot be placed in an external; .js file.
  29. SamJ
    SamJ avatar
    101 posts
    Member since:
    Jul 2008

    Posted 20 Feb 2009 Link to this post

    Well, I am afraid I am out of ideas and cannot help you.
    I hope you find resolution for your issues soon.

    SamJ
  30. Albert Shenker
    Albert Shenker avatar
    567 posts
    Member since:
    Mar 2004

    Posted 20 Feb 2009 Link to this post

    Thanks for the attempt! Is anyone from Telerik out there?
Back to Top