can't access label in code behind

3 posts, 0 answers
  1. Issac
    Issac avatar
    21 posts
    Member since:
    Mar 2012

    Posted 06 Nov 2012 Link to this post

    <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. Issac
    Issac avatar
    21 posts
    Member since:
    Mar 2012

    Posted 06 Nov 2012 Link to this post

    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"
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Leon
    Leon avatar
    5 posts
    Member since:
    May 2012

    Posted 03 Dec 2012 Link to this post

    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.

Back to Top