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

can't access label in code behind

2 Answers 231 Views
ToolBar
This is a migrated thread and some comments may be shown as answers.
Issac
Top achievements
Rank 1
Iron
Issac asked on 06 Nov 2012, 03:43 PM
<telerik:RadToolBar ID="RadToolBar1" runat="server" Skin="Office2010Blue" OnButtonClick="RadToolBar1_ButtonClick" EnableRoundedCorners="true" EnableShadows="true" Width="100%">
            <ExpandAnimation Type="OutQuart" Duration="300"></ExpandAnimation>
            <CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation>
            <Items>
                <telerik:RadToolBarButton>
                    <ItemTemplate>
                        <div style="margin: 0 5px 0 15px;width:620px;">
                            <asp:Label ID="lblCategory" runat="server" Text="CategotyText"></asp:Label> </div>
                    </ItemTemplate>
                </telerik:RadToolBarButton>
                <telerik:RadToolBarDropDown Text="Sort">
                    <Buttons>
                        <telerik:RadToolBarButton Text="New Arrivals">
                        </telerik:RadToolBarButton>
                        <telerik:RadToolBarButton Text="Unordered">
                        </telerik:RadToolBarButton>
                    </Buttons>
                </telerik:RadToolBarDropDown>
            </Items>
        </telerik:RadToolBar>


Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
      Dim Item As RadToolBarItem = RadToolBar1.Items(0)
      Dim lbl As TextBox = TryCast(Item.FindControl("lblCategory"), TextBox)
      lbl.Text = "Found"
End Sub

What am I doing wrong?

2 Answers, 1 is accepted

Sort by
0
Issac
Top achievements
Rank 1
Iron
answered on 06 Nov 2012, 03:48 PM
Found me mistake, had Textbox in there instead of Label.


Dim Item As RadToolBarItem = RadToolBar1.Items(0)
Dim lbl As Label = TryCast(Item.FindControl("lblCategory"), Label)
lbl.Text = "Found"
0
Leon
Top achievements
Rank 1
answered on 03 Dec 2012, 08:26 AM
You have got the access any of your asp controls in your code section part. The controls have an ID this might sound stupid but perhaps yesterday someone created the view with a snippet label tab and forgot to add an id. You have run at server attribute properly set on new controls.

Tags
ToolBar
Asked by
Issac
Top achievements
Rank 1
Iron
Answers by
Issac
Top achievements
Rank 1
Iron
Leon
Top achievements
Rank 1
Share this question
or