How to Get Controls inside a ItemTemplate of a Toolbar

5 posts, 1 answers
  1. Vuyiswa Maseko
    Vuyiswa Maseko avatar
    187 posts
    Member since:
    Jan 2010

    Posted 19 Jul 2010 Link to this post

    Good Day All

    I have the following defination of a toolbar

                   <telerik:RadToolBar runat="server" ID="RadToolBar1" style="overflow:visible;"
                            Skin="Telerik" Width="994px" Height="121px"
                            onbuttonclick="RadToolBar1_ButtonClick">
    <CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation>
                <Items>
                 <telerik:RadToolBarButton>
                        <ItemTemplate>
                          
                            <div style="padding-left:30px">
                            <asp:Image ID="imgo" ImageUrl="~/images/Picture3.png" runat="server" />
                            <asp:Image ID="imgMore" ImageUrl="~/images/Picture5.png" runat="server" />
                            <asp:TextBox ID="txtSearch" Width="500px"  Height="40px" runat="server" />
                            <asp:ImageButton ID="btnCancel" runat="server" ImageUrl="~/images/Picture11.png" Text="Cancel" />
                              <asp:ImageButton ID="btnSearch" runat="server" OnClick="btnSearch_Click" Text="Search" ImageUrl="~/images/Picture12.png" />  
                            <telerik:RadToolBarButton runat="server" IsSeparator="true"></telerik:RadToolBarButton>
                            <asp:ImageButton ID="btnAttach" runat="server" ImageUrl="~/images/Picture13.png" Text="Add" />
                            <asp:ImageButton ID="btnAdd" runat="server" ImageUrl="~/images/Picture8.png" Text="Add" />
                            <asp:ImageButton ID="btnconfig" runat="server" ImageUrl="~/images/Picture9.png" Text="Config" />
                            <asp:ImageButton ID="btnCommitChanges" runat="server" ImageUrl="~/images/Save All 2.png" Text="Config" />
                            <telerik:GridTextBoxColumnEditor ID="textboxc" runat="server"></telerik:GridTextBoxColumnEditor>
                            
                 
                           </div>                     
                        </ItemTemplate>
                    </telerik:RadToolBarButton>
      
                </Items>
            </telerik:RadToolBar>

    and i want to retrieve the value of a textbox control name txtsearch  that is inside the item template, i have tried to retrieve it like this
    TextBox txtseach = new TextBox();
     
    txtseach =  (TextBox)Page.FindControl("txtSearch");
    but my txtseach comes back as null , while i have entered a value


    Thanks

  2. Yana
    Admin
    Yana avatar
    4554 posts

    Posted 19 Jul 2010 Link to this post

    Hello Vuyiswa,

    Please check this help article which explains how to access controls inside templates.

    Best wishes,
    Yana
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Vuyiswa Maseko
    Vuyiswa Maseko avatar
    187 posts
    Member since:
    Jan 2010

    Posted 20 Jul 2010 Link to this post

    Good Day

    i have looked at that Article and i my markup looks like this now

    <telerik:RadToolBar runat="server" ID="RadToolBar1" style="overflow:visible;"
                            Skin="Telerik" Width="994px" Height="121px"
                            onbuttonclick="RadToolBar1_ButtonClick">
    <CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation>
                <Items>
                 <telerik:RadToolBarButton runat="server" Text="Button 1" Value="txtSearch" >
                        <ItemTemplate>
                          
                            <div style="padding-left:30px">
                            <asp:Image ID="imgo" ImageUrl="~/images/Picture3.png" runat="server" />
                            <asp:Image ID="imgMore" ImageUrl="~/images/Picture5.png" runat="server" />
                            <asp:TextBox ID="txtSearch" Width="500px"  Height="40px" runat="server" />
                            <asp:ImageButton ID="btnCancel" runat="server" ImageUrl="~/images/Picture11.png" Text="Cancel" />
                              <asp:ImageButton ID="btnSearch" runat="server" OnClick="btnSearch_Click" Text="Search" ImageUrl="~/images/Picture12.png" />  
                            <telerik:RadToolBarButton runat="server" IsSeparator="true"></telerik:RadToolBarButton>
                            <asp:ImageButton ID="btnAttach" runat="server" ImageUrl="~/images/Picture13.png" Text="Add" />
                            <asp:ImageButton ID="btnAdd" runat="server" ImageUrl="~/images/Picture8.png" Text="Add" />
                            <asp:ImageButton ID="btnconfig" runat="server" ImageUrl="~/images/Picture9.png" Text="Config" />
                            <asp:ImageButton ID="btnCommitChanges" runat="server" ImageUrl="~/images/Save All 2.png" Text="Config" />
                            <telerik:GridTextBoxColumnEditor ID="textboxc" runat="server"></telerik:GridTextBoxColumnEditor>
                            
                 
                           </div>                     
                        </ItemTemplate>
                    </telerik:RadToolBarButton>
      
                </Items>
            </telerik:RadToolBar>

    and on the server side i am trying to access it like this

    RadToolBarItem textItem = RadToolBar1.FindItemByText("Button 1");
         TextBox txtseach = (TextBox)textItem.FindControl("txtseach");
     
         String tempText  = txtseach.Text;
    and it give me the object not set as instance  it comes back as null

    Is there anything i am doing wrong ?

    Thanks
  5. Answer
    Yana
    Admin
    Yana avatar
    4554 posts

    Posted 23 Jul 2010 Link to this post

    Hi Vuyiswa,

    The id of the textbox in your code is wrong, it should be like this:

    protected void RadToolBar1_ButtonClick(object sender, RadToolBarEventArgs e)
    {
        RadToolBarItem textItem = RadToolBar1.FindItemByText("Button 1");
        TextBox txtseach = (TextBox)textItem.FindControl("txtSearch");
     
        String tempText = txtseach.Text;
     
    }

    Note that the IDs are case-sensitive.

    Kind regards,
    Yana
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  6. Vuyiswa Maseko
    Vuyiswa Maseko avatar
    187 posts
    Member since:
    Jan 2010

    Posted 26 Jul 2010 Link to this post

    Thank you very much Admin. It has worked for me.

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