RadToolBarButton Dynamic ItemTemplate

4 posts, 1 answers
  1. Wes
    Wes avatar
    5 posts
    Member since:
    May 2009

    Posted 27 Aug 2012 Link to this post

    I have been trying to create a RadToolBarButton Dynamically in C# with an ItemTemplate.  Does anyone have an example of how to do the following in code behind?

      <telerik:RadToolBar runat="server" ID="toolBarKeywordSearch" EnableRoundedCorners="true" Style="height35px;"
                    EnableShadows="true" OnButtonClick="toolBarWorkItem_Onclick">
                        <telerik:RadToolBarButton Value="gridToolBarButton" CommandName="SearchTextEntered">
                                <asp:Label ID="lblKeyWord" runat="server" Text="Keyword search:"></asp:Label>
                                <telerik:RadTextBox ID="txtSearchQuery" runat="server" Width="110px" ToolTip="Type to search" />


  2. Answer
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 28 Aug 2012 Link to this post

    Hi Wes,

    Try the following code snippet to achieve your scenario.

    RadToolBarButton ToolBarButton = new RadToolBarButton();
    RadToolBar toolBarKeywordSearch = new RadToolBar();
    protected void Page_Load(object sender, EventArgs e)
            if (!IsPostBack)
                toolBarKeywordSearch.ID = "toolBarKeywordSearch";
                toolBarKeywordSearch.EnableRoundedCorners = true;
                toolBarKeywordSearch.Attributes.Add("Style", "height: 35px;");
                toolBarKeywordSearch.EnableShadows = true;
                toolBarKeywordSearch.ButtonClick += new RadToolBarEventHandler(toolBarKeywordSearch_ButtonClick);
                ToolBarButton.Value = "gridToolBarButton";
                ToolBarButton.CommandName = "SearchTextEntered";
            TextBoxTemplate template = new TextBoxTemplate();
    void toolBarKeywordSearch_ButtonClick(object sender, RadToolBarEventArgs e)
          // your code here
    class TextBoxTemplate : ITemplate
        public void InstantiateIn(Control container)
            Label lblKeyWord = new Label();
            lblKeyWord.ID = "lblKeyWord";
            lblKeyWord.Text = "Keyword search:";
            RadTextBox txtSearchQuery = new RadTextBox();
            txtSearchQuery.ID = "txtSearchQuery";
            txtSearchQuery.Width = Unit.Pixel(110);
            txtSearchQuery.ToolTip = "Type to search";

    Please take a look into this documentation for more information.

    Hope this helps.

  3. DevCraft R3 2016 release webinar banner
  4. Wes
    Wes avatar
    5 posts
    Member since:
    May 2009

    Posted 28 Aug 2012 Link to this post

    I can't believe I missed that link.  I should get more sleep.

    Thanks for your help it works great!
  5. Paul
    Paul avatar
    24 posts
    Member since:
    May 2016

    Posted 28 Jul Link to this post

    Thank you this also helped me. I must have missed that Doc too.
Back to Top