set focus on radtextbox in radpanelbar

6 posts, 0 answers
  1. Datamex
    Datamex avatar
    161 posts
    Member since:
    Jun 2012

    Posted 01 Sep 2011 Link to this post

    Hi!

    I have a question about setting focus on a radtextbox inside a radpanelbar. My code looks like this:
    <telerik:RadPanelBar ID="RadPanelBar" runat="server" Width="100%" OnClientItemExpand="onItemExpand">
        <Items>
          <telerik:RadPanelItem Text="Zoeken" Value="Search">
            <ContentTemplate>
            <asp:Panel ID="ExamSearchPanel" runat="server" DefaultButton="SearchButton">
              <table>
                <tr>
                  <td>
                    <asp:Table runat="server">
                      <asp:TableRow ID="TrainingCompanyRow" runat="server">
                        <asp:TableCell>Opleider:</asp:TableCell>
                        <asp:TableCell><telerik:RadTextBox ID="TrainingCompanyTextBox" runat="server" /></asp:TableCell>
                      </asp:TableRow>

    OnClientItemExpand, I want to set focus to the TrainingCompanyTextBox control with javascript. I've tried different ways of setting focus to the contorl, but i can't find the solution.

    How can I do this?
  2. Kate
    Admin
    Kate avatar
    1898 posts

    Posted 07 Sep 2011 Link to this post

    Hi Datamex,

    With the markup provided you can use the following client-side function in order to find the RadTextBox control that is in a ContentTemplate of a RadPanelBar.
    <script type="text/javascript">
            function findTextBoxInPanelBar(sender, args) {
     
                var panelbar = $find("<%= RadPanelBar1.ClientID %>");
                var item = panelbar.findItemByText("item1");
                var txtbox = item.findControl("TrainingCompanyTextBox");
                //here you can use any property that is needed for the textbox
               //I used set_visible just for testing purpose
                txtbox.set_visible(false);
            }   
        </script>

    You will also need to attach the event handler:
    <telerik:RadPanelBar ID="RadPanelBar1" runat="server" OnClientItemClicking="findTextBoxInPanelBar">


    All the best,
    Kate
    the Telerik team

    Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Datamex
    Datamex avatar
    161 posts
    Member since:
    Jun 2012

    Posted 07 Sep 2011 Link to this post

    Hi Kate,

    I've checked your solution and using set_visible indeed works. But somehow I can't set focus to the control. I've used focus() and add_focus() but none of them works. This is my code:
    function RadPanelBarClientClicking(sender,args) {
        var panelbar = $find("<%= RadPanelBar.ClientID %>");
        var item = panelbar.findItemByText("Zoeken");
        var txtbox = item.findControl("TrainingCompanyTextBox");
        txtbox.focus();
      }

    Is this a bug? When I use add_focus() than the control hasn't focus. If i click the control after that it has focus, but I get some strange errors in the Telerik.Web.UI.WebResource_2.axd.
  5. Kate
    Admin
    Kate avatar
    1898 posts

    Posted 12 Sep 2011 Link to this post

    Hi Datamex,

    Indeed setting focus() to the RadTextBox in a ContentTemplate of a RadPanelBar should work but currently it seems to have a bug. As a workaround I would suggest that you use the ItemTemplate that properly sets focus to the RadTextBox.  

    All the best,
    Kate
    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. Joel Johnston
    Joel  Johnston avatar
    18 posts
    Member since:
    Oct 2005

    Posted 13 Nov 2012 Link to this post

    Is this fixed in current versions?
    Or is there a workaround using ContentTemplate that allows for setting focus to an element in the template?
  7. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 14 Nov 2012 Link to this post

    Hi,

    Here is the sample code that I tried based on your scenario which works fine in Telerik Version 2012, 2, 828, 35.

    JS:
    <script type="text/javascript">
     function findTextBoxInPanelBar(sender, args)
     {
      var panelbar = $find("<%= RadPanelBar1.ClientID %>");
      var item = panelbar.findItemByText("Item1");
      var txtbox = item.findControl("RadTextBox1");
      txtbox.focus();
     }
    </script>

    Hope this helps.

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