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

Accessing a UserControl Within a PanelBar

6 Answers 128 Views
PanelBar
This is a migrated thread and some comments may be shown as answers.
PJ Rodriguez
Top achievements
Rank 1
PJ Rodriguez asked on 29 Oct 2009, 02:46 AM
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.


6 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 29 Oct 2009, 07:09 AM
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.
0
PJ Rodriguez
Top achievements
Rank 1
answered on 29 Oct 2009, 12:33 PM
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.
0
PJ Rodriguez
Top achievements
Rank 1
answered on 29 Oct 2009, 12:51 PM
Here is a screen shot of the error
0
Paul
Telerik team
answered on 29 Oct 2009, 12:58 PM
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.
0
PJ Rodriguez
Top achievements
Rank 1
answered on 29 Oct 2009, 03:32 PM
Hi Paul,

Thanks. I have opened a support ticket (254299)

Thanks.
0
PJ Rodriguez
Top achievements
Rank 1
answered on 02 Nov 2009, 08:09 AM
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.


Tags
PanelBar
Asked by
PJ Rodriguez
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
PJ Rodriguez
Top achievements
Rank 1
Paul
Telerik team
Share this question
or