Accessing a UserControl Within a PanelBar

7 posts, 0 answers
  1. PJ Rodriguez
    PJ  Rodriguez avatar
    37 posts
    Member since:
    Feb 2005

    Posted 28 Oct 2009 Link to this post

    I have a radPanelBar called rpbAgenda.

    I have a user control located within this panel bar called abConsent. This user control has several properties that I have exposed such as idCouncilMtgDate, Title, etc that I can set programmatically.

    Below is my HTML code for the user control:

    <telerik:RadPanelItem value="Consent" Text="Consent Agenda - Action Items" Font-Bold="True" BorderStyle="None"
                    <Items> 
                        <telerik:RadPanelItem> 
                            <ItemTemplate> 
                                <uc1:ab ID="abConsent1" runat="server" Visible="true" /> 
                            </ItemTemplate> 
                        </telerik:RadPanelItem> 
                    </Items> 
                </telerik:RadPanelItem> 


    In a normal occurrence, I can set the properties of this user control by the following:
    abConsent1.idCouncilMeetingDate = rcmbCouncilMtgDate.SelectedValue 
            abConsent1.isConsentAgenda = "Yes" 
            abConsent1.isOrdinance = "No" 
            abConsent1.isApproved = "Yes" 
            abConsent1.idCommittee = "%" 
            abConsent1.title = "<b>Other Approvals</b>" 

    However, since this user control is nested within a panelbar, I am unable to access it. I've tried the following but I was unsuccessful:

    Dim abconsent1 As ab = rpbAgenda.FindControl("abconsent1"

    How can I access the user control and its corresponding exposed properties? Thanks. I've taken a look at the samples but seem to have run into a dead end no matter what.


  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 29 Oct 2009 Link to this post

    Hello,

    Since the UserControl is placed inside a RadPanelItem as ItemTemplate, you have to get the reference to corresponding RadPanelItem and then access the usercontrol using FindControl() method.

    VB:
     
    Protected Sub Button2_Click(ByVal sender As ObjectByVal e As EventArgs) 
        ' access the panel item   
        Dim item As RadPanelItem = DirectCast(RadPanelBar2.Items(0), RadPanelItem)     
        Dim uc As UserControl = DirectCast(item.FindControl("abConsent1"), UserControl) 
        ' Set the properties of uc         
    End Sub 

    -Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. PJ Rodriguez
    PJ  Rodriguez avatar
    37 posts
    Member since:
    Feb 2005

    Posted 29 Oct 2009 Link to this post

    Hi Shinu,

    Thank you for your response. Unfortunately, that did not seem to fix the issue. I tried your fix and what happens is that now I am unable to expose the properties of the user control (Visual Studio gives me a compile error--please see the attached screen cap)

    Dim item As RadPanelItem = DirectCast(rpbAgenda.Items(4), RadPanelItem) 
            Dim abconsent As UserControl = DirectCast(item.FindControl("abConsent1"), UserControl) 
     
            abConsent.idCouncilMeetingDate = rcmbCouncilMtgDate.SelectedValue 
            abConsent.isConsentAgenda = "Yes" 
            abConsent.isOrdinance = "No" 
            abConsent.isApproved = "Yes" 
            abConsent.idCommittee = "%" 
            abconsent.title = "<b>Other Approvals</b>" 

    Any other suggestions? Thanks.
  5. PJ Rodriguez
    PJ  Rodriguez avatar
    37 posts
    Member since:
    Feb 2005

    Posted 29 Oct 2009 Link to this post

    Here is a screen shot of the error
  6. Paul
    Admin
    Paul avatar
    4281 posts

    Posted 29 Oct 2009 Link to this post

    Hello PJ Rodriguez,

    Could you please open a support ticket and send a simple running project (incl. CSS, images, DB backup and so on) demonstrating the problems. In that way we can reproduce and pinpoint the problems you're facing on our side, understand the logic of your application and provide a solution.

    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.
  7. PJ Rodriguez
    PJ  Rodriguez avatar
    37 posts
    Member since:
    Feb 2005

    Posted 29 Oct 2009 Link to this post

    Hi Paul,

    Thanks. I have opened a support ticket (254299)

    Thanks.
  8. PJ Rodriguez
    PJ  Rodriguez avatar
    37 posts
    Member since:
    Feb 2005

    Posted 02 Nov 2009 Link to this post

    Upon further research, I was able to resolve this issue (make the FindControl function work).

    It was actually just one line of code as opposed to the multiple lines of code that are in the Telerik demos and samples:
    Dim abconsent1 As ab = CType(rpbagenda.FindItemByValue("Consent").FindControl("abconsent"), ab) 

    In the case above, ab is my usercontrol tag/type. abconsent is the id of the usercontrol and consent is the value of the RADpanel item the user control is located in. The Telerik samples showed the use of the FindItemByValue from specific panel items. The problem with that is that the FindControl method is then limited to that specific panel item. Calling the FindItemByValue this way iterates through all the panel items within the PanelBar.


Back to Top
UI for ASP.NET Ajax is Ready for VS 2017