RadCalendar inside dynamically loaded usercontrol

4 posts, 0 answers
  1. Nuno
    Nuno avatar
    53 posts
    Member since:
    Dec 2007

    Posted 24 Feb 2010 Link to this post


    Hi all,

    I have a Web Page which contains a RadMenu and a ASP Panel.

    Everytime a user clicks on a RadMenuItem I'm loading dynamically a usercontrol:

            Panel.Controls.Clear();
            UserControl c = (UserControl)LoadControl("~/UserControls/" + userControl.TrimEnd());
            c.ID = c.ToString();        
            Panel.Controls.Add(c);

    The problem is that in this new usercontrol I'm trying to recreate below demo just like it is, inside the usercontrol:

    It doesn't work at all! The RadCalendar doesn't even fire RadCalendar1_SelectionChanged event!

    Can you provide me a simple example/project accomplishing this ? ? ?

    (I have tried recreating this demo inside a normal Web Page and it works fine)

    I'm using VS2008 SP1 with Telerik AJAX 2009.3.1314.35

    Thanks for your help.

    Nuno




  2. Radoslav
    Admin
    Radoslav avatar
    1566 posts

    Posted 01 Mar 2010 Link to this post

    Hello Nuno,

    When adding a user control that contains a RadControls instance into a panel at, the events for the user control may not fire on postback unless you load the control in the Page_Load event of the main page.
    The problem with loading a user control at a later time (for example inside the server-side event handler of another control on the page) is that the browser cannot send your page events for controls that don't exist. Even if the controls are added at runtime the last time the code ran, at a later stage their events can't fire.

    So I suggest you to add your UserControl into the Page.Load event:

    protected void Page_Load(object sender, EventArgs e)
    {
     if (Page.FindControl("myUC") == null)
     {
            UserControl c = (UserControl)LoadControl("~/UserControls/" + userControl.TrimEnd());
            c.ID = "myUC";       
            Panel.Controls.Add(c);
     }
    }

    Also you could check out the following online docuementation article wuch explanes how to load dynamically user controls:
    http://www.telerik.com/help/aspnet-ajax/ajxloadusercontrols.html

    I hope this helps.

    Regards,
    Radoslav
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. Nuno
    Nuno avatar
    53 posts
    Member since:
    Dec 2007

    Posted 01 Mar 2010 Link to this post


    Hi Radoslav,

    Thanks for your reply.

    In my case, what triggers the usercontrols to load dynamically is the RadMenu1_ItemClick event, which happens right after the Page_Load method.  What do you suggest as a workaroud ?

    Best Regards,
    Nuno


  4. Radoslav
    Admin
    Radoslav avatar
    1566 posts

    Posted 04 Mar 2010 Link to this post

    Hello Nuno,

    When the menu's item is selected you could save its value into the asp:HiddenField via JavaScript. In the Page.OnLoad event handler you could check out which menu item was chosen, by getting value from the asp:HiddenField and then load the corresponding UserControl.

    I hope this helps.

    Sincerely yours,
    Radoslav
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Back to Top