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

How to Get Controls inside a ItemTemplate of a Toolbar

4 Answers 226 Views
ToolBar
This is a migrated thread and some comments may be shown as answers.
Vuyiswa
Top achievements
Rank 2
Vuyiswa asked on 19 Jul 2010, 03:30 PM
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

4 Answers, 1 is accepted

Sort by
0
Yana
Telerik team
answered on 19 Jul 2010, 04:42 PM
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
0
Vuyiswa
Top achievements
Rank 2
answered on 20 Jul 2010, 07:39 AM
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
0
Accepted
Yana
Telerik team
answered on 23 Jul 2010, 08:51 AM
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
0
Vuyiswa
Top achievements
Rank 2
answered on 26 Jul 2010, 11:06 AM
Thank you very much Admin. It has worked for me.

Thanks
Tags
ToolBar
Asked by
Vuyiswa
Top achievements
Rank 2
Answers by
Yana
Telerik team
Vuyiswa
Top achievements
Rank 2
Share this question
or