PanelBar accessing UserControl functions

7 posts, 0 answers
  1. Moon
    Moon avatar
    249 posts
    Member since:
    Oct 2012

    Posted 28 Aug 2009 Link to this post

    I have radpanelbar defined in my code in front with an embedded user control.

    <telerik:RadPanelBar ID="RadPanelBar1" runat="server">  
        <Items runat="server">  
            <telerik:RadPanelItem ID="RadPanelItem1" runat="server">  
                <uc:ComponentDescriptionPurpose ID="ComponentDescriptionPurpose" runat="server" /> 
            </telerik:RadPanelItem> 
        </Items> 
    </telerik:RadPanelBar> 

    In the code-behind, I need to access a function within the user control. I tried below to find it, but it doesn't work.
    How do I find it within the panelbar so I can access its functions?
            Dim ComponentDescriptionPurpose As Telerik.Web.UI.RadPanelBar = DirectCast(Page.FindControl("ComponentDescriptionPurpose"), Telerik.Web.UI.RadPanelBar)  
     
            ComponentDescriptionPurpose.LoadByOrm(idKey) 

    Thanks.

  2. Paul
    Admin
    Paul avatar
    4281 posts

    Posted 28 Aug 2009 Link to this post

    Hello Moon,

    Here's a sample code snippet that shows the needed approach.

    ASPX:
    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default2.aspx.vb" Inherits="Default2" %> 
     
    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> 
    <%@ Register Src="WebUserControl.ascx" TagName="WebUserControl" TagPrefix="uc1" %> 
    <!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></title
    </head> 
    <body> 
        <form id="form1" runat="server"
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server"
        </telerik:RadScriptManager> 
        <telerik:RadPanelBar ID="RadPanelBar1" runat="server"
            <Items runat="server"
                <telerik:RadPanelItem ID="RadPanelItem1" runat="server" Text="Root RadPanelItem1" 
                    Expanded="true"
                    <Items> 
                        <telerik:RadPanelItem runat="server" Value="templateHolder"
                            <ItemTemplate> 
                                <uc1:WebUserControl ID="WebUserControl1" runat="server" /> 
                            </ItemTemplate> 
                        </telerik:RadPanelItem> 
                    </Items> 
                </telerik:RadPanelItem> 
            </Items> 
        </telerik:RadPanelBar> 
        </form> 
    </body> 
    </html> 
     

    Code-behind:
    Imports Telerik.Web.UI 
     
    Partial Class Default2 
        Inherits System.Web.UI.Page 
     
        Protected Sub Page_Load(ByVal sender As ObjectByVal e As System.EventArgs) Handles Me.Load 
            Dim txtb As TextBox = DirectCast(RadPanelBar1.FindItemByValue("templateHolder").FindControl("WebUserControl1").FindControl("TextBox1"), TextBox) 
            txtb.Text = "test" 
        End Sub 
    End Class 
     


    Greetings,
    Paul
    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. UI for ASP.NET Ajax is Ready for VS 2017
  4. Moon
    Moon avatar
    249 posts
    Member since:
    Oct 2012

    Posted 28 Aug 2009 Link to this post

    I tried that, but I want to access a function of the control itself. How do I call the function within the control?

    thanks.
  5. Paul
    Admin
    Paul avatar
    4281 posts

    Posted 31 Aug 2009 Link to this post

    Hello Moon,


    I'm afraid your question is not related to any Telerik control. I suggest you google for a possible solutions on the matter, For example, you can start from these articles:

    http://stackoverflow.com/questions/603419/public-methods-inside-user-control-c-net
    http://stackoverflow.com/questions/360836/call-function-in-user-control-from-code-behind-of-the-page

    Greetings,
    Paul
    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. Moon
    Moon avatar
    249 posts
    Member since:
    Oct 2012

    Posted 16 Sep 2009 Link to this post

    You did finally provide me with the solution via the support tickets... So I thought I should share it with others who want to know:

    Codebehind:

                Dim ComponentDescriptionPurpose As ComponentDescriptionPurpose = DirectCast(RadPanelBar1.FindItemByValue("templateComponentDescriptionPurpose").FindControl("ComponentDescriptionPurpose"), ComponentDescriptionPurpose)  
                ComponentDescriptionPurpose.LoadByOrm(ReviewId) 

    Here is the user control setup, code in front:
            <telerik:RadPanelItem ID="RadPanelItemComponentDescriptionPurpose" runat="server">  
                <Items> 
                    <telerik:RadPanelItem runat="server" Value="templateComponentDescriptionPurpose">  
                        <ItemTemplate> 
                            <uc:ComponentDescriptionPurpose ID="ComponentDescriptionPurpose" runat="server" /> 
                        </ItemTemplate> 
                    </telerik:RadPanelItem> 
                </Items> 
            </telerik:RadPanelItem> 
  7. mathieu cupryk
    mathieu cupryk avatar
    27 posts
    Member since:
    Jul 2009

    Posted 11 Dec 2009 Link to this post

     

    TextBox txtZipCode = (TextBox)RadPanelBar2.FindItemByValue("GeneralInformation").FindControl("ctrlAboutMe").FindControl("txtZipCode");

    trying to get the text box.

     

     

    <telerik:RadPageView ID="RadPageView2" runat="server">

     

     

     

     

     

    <telerik:RadAjaxPanel ID="RadAjaxPanel2" runat="server">

     

     

     

     

     

    <telerik:RadPanelBar ID="RadPanelBar2" runat="server" Skin="WebBlue" ExpandMode="FullExpandedItem"

     

     

     

     

     

    Width="100%" Height="600px">

     

     

     

     

     

    <Items>

     

     

     

     

     

    <telerik:RadPanelItem runat="server" Text="GENERAL INFORMATION" Font-Bold="true"

     

     

     

     

     

    Expanded="true">

     

     

     

     

     

    <Items>

     

     

     

     

     

    <telerik:RadPanelItem Value="GeneralInformation" runat="server">

     

     

     

     

     

    <ItemTemplate>

     

     

     

     

     

    <uc2:ctrlAboutMe ID="ctrlAboutMe" runat="server" />

     

     

     

     

     

    <uc5:ctrlVisitorInformation ID="ctrlVisitorInformation" runat="server" />

     

     

     

     

     

    </ItemTemplate>

     

     

     

     

     

    </telerik:RadPanelItem>

     

     

     

     

     

    </Items>

     

     

     

     

     

    </telerik:RadPanelItem>

     

     

     

     

     

    <telerik:RadPanelItem runat="server" Text="PHYSICAL CHARACTERISTICS" Font-Bold="true">

     

     

     

     

     

    <Items>

     

     

     

     

     

    <telerik:RadPanelItem runat="server">

     

     

     

     

     

    <ItemTemplate>

     

     

     

     

     

    <uc3:ctrlPhysicalAttributes ID="ctrlPhysicalAttributes" runat="server" />

     

     

     

     

     

    </ItemTemplate>

     

     

     

     

     

    </telerik:RadPanelItem>

     

     

     

     

     

    </Items>

     

     

     

     

     

    </telerik:RadPanelItem>

     

     

     

     

     

    <telerik:RadPanelItem runat="server" Text="LIFESYLE AND HABBITS" Font-Bold="true">

     

     

     

     

     

    <Items>

     

     

     

     

     

    <telerik:RadPanelItem runat="server">

     

     

     

     

     

    <ItemTemplate>

     

     

     

     

     

    <uc4:ctrlLifeStyle ID="ctrlLifeStyle" runat="server" />

     

     

     

     

     

    </ItemTemplate>

     

     

     

     

     

    </telerik:RadPanelItem>

     

     

     

     

     

    </Items>

     

     

     

     

     

    </telerik:RadPanelItem>

     

     

     

     

     

    <telerik:RadPanelItem runat="server" Text="RELATIONSHIPS AND CHILDREN" Font-Bold="true">

     

     

     

     

     

    <Items>

     

     

     

     

     

    <telerik:RadPanelItem runat="server">

     

     

     

     

     

    <ItemTemplate>

     

     

     

     

     

    <uc6:ctrlRelationshipChildren ID="ctrlRelationshipChildren" runat="server" />

     

     

     

     

     

    </ItemTemplate>

     

     

     

     

     

    </telerik:RadPanelItem>

     

     

     

     

     

    </Items>

     

     

     

     

     

    </telerik:RadPanelItem>

     

     

     

     

     

    </Items>

     

     

     

     

     

    </telerik:RadPanelBar>

     

     

     

     

     

    </telerik:RadAjaxPanel>

     

     

     

     

     

    <br />

     

     

     

     

     

    <div id="saveButton">

     

     

     

     

     

    <asp:Button ID="SaveButton" OnClick="SaveButton_Click" Height="20px" Font-Size="10px" runat="server" Text="Save"

     

     

     

     

     

    Visible="true" />

     

     

     

     

     

    </div>

     

     

     

     

     

    </telerik:RadPageView>

     

  8. Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts

    Posted 16 Dec 2009 Link to this post

    Hi mathieu cupryk,

    Please find attached a sample project based on your code. It works as expected on my side.

    Kind regards,
    Veselin Vasilev
    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.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017