Edit this page

Accessing Controls Inside Templates

If your RadToolBar has items with templates that have embedded controls, you may want to access the properties of those embedded controls. To get a reference to the embedded control, locate the RadToolBarItem that has the template, and use its FindControl method.

For example, consider the following, very simple, toolbar:

<telerik:RadToolBar RenderMode="Lightweight" ID="RadToolBar1" runat="server">
        <telerik:RadToolBarButton runat="server" Text="Button 1" Value="TextBox1">
                <asp:TextBox ID="TextBox1" runat="server" Text='<%# DataBinder.Eval(Container, "Value") %>' />
        <telerik:RadToolBarButton runat="server" Text="Button 2" />

To access the TextBox in the item template, use the following code:

RadToolBarItem textItem = RadToolBar1.FindItemByText("Button 1");
TextBox textBox = (TextBox) textItem.FindControl("TextBox1");               
Dim textItem As RadToolBarItem = RadToolBar1.FindItemByText("Button 1")
Dim textBox As TextBox = CType(textItem.FindControl("TextBox1"), TextBox)   

You can also acces different controls place in an Item of the RadToolBar control from the client-side For example having the following code you can get to the RadButton by finding the RadToolbarButton first:

<script type="text/javascript">
function OnClientLoad() {
    var toolBar = $find("<%= RadToolbar1.ClientID %>");
    var toolbarbutton = toolBar.findItemByValue("Paste")
    var radbutton = toolbarbutton.findControl("Button1"); //for RadControls
    var button1 = $telerik.findElement(toolbarbutton.get_element(), ("Print")); //to find a generic HTML element 
<telerik:RadToolBar RenderMode="Lightweight" ID="RadToolbar1" runat="server" OnClientLoad="OnClientLoad">
        <telerik:RadToolBarButton Text="Copy" Value="Copy">
        <telerik:RadToolBarButton Value="Paste">
                <telerik:RadButton RenderMode="Lightweight" ID="Button1" runat="server" Text="Button1" />
                <asp:Button ID="Print" Text="Print" runat="server" />

See Also

Is this article helpful? No Yes
Thank you for your feedback!

Give article feedback

Tell us how we can improve this article