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

Add User Control Programmatically To RadPanelBar

3 Answers 326 Views
PanelBar
This is a migrated thread and some comments may be shown as answers.
jfkrueger
Top achievements
Rank 1
jfkrueger asked on 21 Dec 2008, 06:10 PM
<telerik:RadPanelBar   
    ID="rpbCSRLists"   
    runat="server"   
    ExpandMode="SingleExpandedItem"   
    AllowCollapseAllItems="true"   
    Width="100%"   
    PersistStateInCookie="true" 
    OnClientItemExpand="OnClientItemExpand">  
 
        <Items> 
 
            <telerik:RadPanelItem Text="Alternative Words to Search In Plan Documents" Selected="true">  
                  
                <Items>    
                  
                    <telerik:RadPanelItem> 
                      
                        <ItemTemplate> 
                               
                            <CSR:AlternativeWords ID="uctAlternativeWords" runat="server" /> 
                              
                        </ItemTemplate>      
                      
                    </telerik:RadPanelItem> 
                  
                </Items> 
                  
            </telerik:RadPanelItem> 
              
        </Items> 
 
    </telerik:RadPanelBar> 

Instead of adding my User Control declaratively, how would I go about adding this user control programmatically when the panel bar is clicked? I know I can use the ItemClicked event but actually adding the control is giving me problems ("cannot add control to literal control etc). I just can't seem to get the heirarcy right to find where I should be adding the control.

Thanks!

3 Answers, 1 is accepted

Sort by
0
jfkrueger
Top achievements
Rank 1
answered on 23 Dec 2008, 07:42 PM
I have followed this example to try and accomplish what I need:

http://www.telerik.com/help/aspnet-ajax/radpanelbar-dynamically-created-radmenu.html

However it is not working, the control is not added to the PanelItem, there is nothing there when it expands.

Here is my code:

<telerik:RadPanelBar   
    ID="rpbCSRLists"   
    runat="server"   
    ExpandMode="SingleExpandedItem"   
    AllowCollapseAllItems="true"   
    Width="100%"   
    PersistStateInCookie="true" 
    OnClientItemExpand="OnClientItemExpand" 
    OnClientItemCollapse="OnClientItemCollapse">  
 
    <Items> 
 
        <telerik:RadPanelItem runat="server" Text="Alternative Words to Search In Plan Documents" Selected="true">  
              
            <Items>   
              
                <telerik:RadPanelItem runat="server" Value="alternativeWordsTemplateHolder">                      
                      
                  
                </telerik:RadPanelItem> 
              
            </Items> 
              
        </telerik:RadPanelItem>   
                      
    </Items> 
 
</telerik:RadPanelBar> 
 

Protected Sub rpbCSRLists_ItemClick(ByVal sender As ObjectByVal e As Telerik.Web.UI.RadPanelBarEventArgs) Handles rpbCSRLists.ItemClick  
 
    Dim panelItem As Telerik.Web.UI.RadPanelItem = Nothing   
    Dim uctControl As Object = Nothing   
 
    Select Case e.Item.Index  
      Case 0  
            uctControl = New UserControls_CSRParts_AlternativeWordsList  
            panelItem = DirectCast(rpbCSRLists.FindItemByValue("alternativeWordsTemplateHolder"), Telerik.Web.UI.RadPanelItem)  
            panelItem.Controls.Add(uctControl)  
    End Select 
 
End Sub 
 

How can I get this to work? I have many RadPanelItems each containing a WebUserControl with a pretty hefty grid on each. This is causing a huge ViewState and the grids to be very slow when sorting, filtering, etc. I just want the control loaded if the user actually clicks on that RadPanelItem.

Thanks!
0
jfkrueger
Top achievements
Rank 1
answered on 23 Dec 2008, 07:52 PM
It works fine if I add a normal asp.net control, but does not work when adding a WebUserControl...
0
jfkrueger
Top achievements
Rank 1
answered on 29 Dec 2008, 04:19 PM

How come you guys mark this post as "closed" when it has not been resolved? In any case, here is how I was able to do it:

Dim uc As Control = Page.LoadControl("uc_form.ascx")   
myPlaceHolder.Controls.Add(uc)   
 
 
Tags
PanelBar
Asked by
jfkrueger
Top achievements
Rank 1
Answers by
jfkrueger
Top achievements
Rank 1
Share this question
or