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

RadCalendar inside dynamically loaded usercontrol

3 Answers 90 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
Nuno
Top achievements
Rank 1
Nuno asked on 25 Feb 2010, 03:51 AM

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




3 Answers, 1 is accepted

Sort by
0
Radoslav
Telerik team
answered on 01 Mar 2010, 08:46 AM
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.
0
Nuno
Top achievements
Rank 1
answered on 01 Mar 2010, 08:36 PM

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


0
Radoslav
Telerik team
answered on 04 Mar 2010, 03:00 PM
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.
Tags
Calendar
Asked by
Nuno
Top achievements
Rank 1
Answers by
Radoslav
Telerik team
Nuno
Top achievements
Rank 1
Share this question
or