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

Set focus on TextBox in a RadTooltip

1 Answer 123 Views
ToolTip
This is a migrated thread and some comments may be shown as answers.
Muhammad
Top achievements
Rank 1
Muhammad asked on 12 Oct 2012, 01:41 PM
Hi All,

I am using RadToolTip control and under that I have place a textbox control when a user click on a radtooltip I would like to set the focus on a textbox control. For some reason I am not able to that. Please look at the code below and advise me anything which might be useful for me.

I am getting the textNote ID but for some reason when I call the focus method it doesn't set the focus.


Thanks for your response in advance.





<script type="text/javascript">
 
       function SetFocusToTextBox(txt) {
 
           var txtNote = document.getElementById(txt);
           alert(txtNote);
           txtNote.focus();
       }
 
   </script>




<telerik:RadGrid ID="gvTopics" runat="server" Font-Names="Verdana" Font-Size="XX-Small"
            Skin="Office2007" EnableEmbeddedSkins="true" GridLines="Both" AllowSorting="true"
            AllowPaging="true" PageSize="10" Width="99%" CellPadding="2" AutoGenerateColumns="False">
            <MasterTableView CommandItemDisplay="Top">
                <CommandItemSettings ShowAddNewRecordButton="false" RefreshImageUrl="" />
                <Columns>
                    <telerik:GridTemplateColumn>
                        <ItemTemplate>
                            <asp:ImageButton ID="btnShowMessagesFromTopicList" ToolTip="Show messages" runat="server"
                                CommandArgument='<%# Container.DataItem("id")%>' Text="show msgs" OnClick="btnShowMessagesFromTopicList_Click" />
                             <asp:ImageButton ID="btnAddMessage" runat="server" ToolTip="Reply to agent"
                                Text="Reply" CommandArgument='<%# Container.DataItem("id")%>' OnClick="btnReply_Click" />
                             <asp:ImageButton ID="btnAddNote" runat="server" Text="Add Note" CommandArgument='<%# Container.DataItem("id")%>' />
                             <asp:ImageButton ID="btnCloseTopic" runat="server" Text="close" Visible="false"
                                CommandArgument='<%# Container.DataItem("id")%>' OnClick="btnCloseTopic_Click"
                                ToolTip="Close topic" />
                            <asp:HiddenField ID="hidID" Value='<%# Bind("ID") %>' runat="server" />
                            <asp:HiddenField ID="hidCreatedBy" Value='<%# Bind("CreatedBy") %>' runat="server" />
                            <asp:HiddenField ID="hidNewAgentMessage" Value='<%# Bind("NewAgentMessage") %>' runat="server" />
                            <telerik:RadToolTip ID="rttpNote" Width="210" Height="200" HideEvent="ManualClose"
                                TargetControlID="btnAddNote" RelativeTo="Element" Skin="Windows7" Position="TopRight"
                                ManualClose="true" ShowEvent="OnClick" runat="server">
                                <table width="100%">
                                    <tr>
                                        <td>
                                            Notes :
                                            <asp:TextBox ID="txtNote" TextMode="MultiLine" Width="200" Height="200" onblur runat="server"></asp:TextBox>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>
                                            <asp:Button ID="btnSaveNote" CommandArgument='<%# Container.DataItem("id")%>' Text="Save"
                                                OnClick="btnSaveNote_Click" runat="server" />
                                        </td>
                                    </tr>
                                </table>
                            </telerik:RadToolTip>
                        </ItemTemplate>
                        <ItemStyle Width="15%" />
                    </telerik:GridTemplateColumn>
                </Columns>
            </MasterTableView>
        </telerik:RadGrid>



  Protected Sub gvTopics_OnItemDataBound(ByVal sender As Object, ByVal e As GridItemEventArgs) Handles gvTopics.ItemDataBound


        If TypeOf (e.Item) Is GridDataItem Then         

            Dim txtNote As TextBox = e.Item.FindControl("txtNote")             
            btnAddNote.Attributes.Add("onClick", "javascript:SetFocusToTextBox('" & txtNote.ClientID & "')")        

    End Sub

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 15 Oct 2012, 07:36 AM
Hi Muhammad,

Here is the sample code that I tried to set focus in the textbox.
VB:
Protected Sub RadGrid1_ItemDataBound(sender As Object, e As Telerik.Web.UI.GridItemEventArgs)
    If TypeOf e.Item Is GridDataItem Then
        Dim item As GridDataItem = DirectCast(e.Item, GridDataItem)
        Dim txtNote As TextBox = DirectCast(item.FindControl("txtNote"), TextBox)
        Dim btnAddNote As ImageButton = DirectCast(item.FindControl("btnAddNote"), ImageButton)
        btnAddNote.Attributes.Add("onclick", "SetFocusToTextBox('" + txtNote.ClientID + "');return false;")
    End If
End Sub
JS:
function SetFocusToTextBox(txt)
{
 var txtNote = $get(txt);
 txtNote.focus();
}

Thanks,
Shinu.
Tags
ToolTip
Asked by
Muhammad
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or