This is a migrated thread and some comments may be shown as answers.
set focus on radtextbox in radpanelbar
5 Answers 77 Views
This is a migrated thread and some comments may be shown as answers.
Datamex
Top achievements
Rank 2
Datamex asked on 01 Sep 2011, 11:44 AM
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?

5 Answers, 1 is accepted

Sort by
0
Kate
Telerik team
answered on 07 Sep 2011, 01:29 PM
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 >>

0
Datamex
Top achievements
Rank 2
answered on 07 Sep 2011, 01:50 PM
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.
0
Kate
Telerik team
answered on 12 Sep 2011, 01:02 PM
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
0
Joel Johnston
Top achievements
Rank 1
answered on 13 Nov 2012, 09:07 PM
Is this fixed in current versions?
Or is there a workaround using ContentTemplate that allows for setting focus to an element in the template?
0
Princy
Top achievements
Rank 1
answered on 14 Nov 2012, 06:52 AM
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.
Asked by
Datamex
Top achievements
Rank 2
Answers by
Kate
Telerik team
Datamex
Top achievements
Rank 2
Joel Johnston
Top achievements
Rank 1
Princy
Top achievements
Rank 1
Share this question
or