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

Cannot access asp controls in rad panel bar

2 Answers 93 Views
PanelBar
This is a migrated thread and some comments may be shown as answers.
khalid
Top achievements
Rank 1
khalid asked on 22 Jan 2009, 07:54 AM
Hello,

I am using a rad panel bar in which i have buttons, now i want to change the button css from the code behind but the button is inaccessible.

here is the code snippet


<

 

telerik:RadPanelBar runat="server" ID="RadPanelBar1" BorderColor="transparent" BackColor="transparent"

 

 

AllowCollapseAllItems="true" Style="" Height="550px" Width="200px" ExpandMode="singleExpandedItem"

 

 

Skin="Telerik">

 

 

<Items>

 

 

<telerik:RadPanelItem Text="Home" Expanded="True" runat="server">

 

 

<Items>

 

 

<telerik:RadPanelItem runat="server">

 

 

<ItemTemplate>

 

 

<asp:LinkButton ID="LinkButton13" runat="server" CssClass="MyGridView" OnClick="LinkButton13_Click"

 

 

Height="25px" Width="200px" Font-Names="Verdana" Font-Size="8pt" Font-Underline="False"

 

 

ForeColor="Blue" OnClientClick="javascript:ToggleCollapsePane('LeftPane')">

 

 

National</asp:LinkButton>

 

 

</ItemTemplate>

 

 

</telerik:RadPanelItem>

 

 

</Items>

 

 

</telerik:RadPanelItem>

 

 

</Items>

 

 

</telerik:RadPanelBar>


code behind

 

 

protected void LinkButton13_Click(object sender, EventArgs e)

 

{

 

LinkButton13.CssClass="Test";

}
 

it is displaying error "linkbutton13 does not exist in the current context" 

 

 

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 22 Jan 2009, 10:30 AM
Hello Khalid,

Try out the following code to set the css class for the linkbutton inside the RadPanelItem on clicking the linkbutton.
cs:
protected void LinkButton13_Click(object sender, EventArgs e) 
    { 
        LinkButton lnkbtn = (LinkButton)sender; 
        lnkbtn.CssClass = "Test"
    } 

Thanks
Princy.
0
Paul
Telerik team
answered on 22 Jan 2009, 11:43 AM
Hello Khalid,

You have to use the FindControl() method to get reference to the templated control(s).

ASPX:
<telerik:RadPanelBar runat="server" ID="RadPanelBar1" BorderColor="transparent" BackColor="transparent" 
    AllowCollapseAllItems="true" Style="" Height="550px" Width="200px" ExpandMode="singleExpandedItem" 
    Skin="Telerik"
    <Items> 
        <telerik:RadPanelItem Text="Home" Expanded="True" runat="server"
            <Items> 
                <telerik:RadPanelItem runat="server" Value="templateHolder"
                    <ItemTemplate> 
                        <asp:LinkButton ID="LinkButton13" runat="server" CssClass="MyGridView" OnClick="LinkButton13_Click" 
                            Height="25px" Width="200px" Font-Names="Verdana" Font-Size="8pt" Font-Underline="False" 
                            ForeColor="Blue" OnClientClick="javascript:ToggleCollapsePane('LeftPane')">National</asp:LinkButton> 
                    </ItemTemplate> 
                </telerik:RadPanelItem> 
            </Items> 
        </telerik:RadPanelItem> 
    </Items> 
</telerik:RadPanelBar> 

Code-behind:
protected void LinkButton13_Click(object sender, EventArgs e) 
    LinkButton myLinkButton = (LinkButton)RadPanelBar1.FindItemByValue("templateHolder").FindControl("LinkButton13"); 
    myLinkButton.CssClass = "Test"


Best wishes,
Paul
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
PanelBar
Asked by
khalid
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Paul
Telerik team
Share this question
or