Set focus on TextBox in a RadTooltip

2 posts, 0 answers
  1. Muhammad
    Muhammad avatar
    87 posts
    Member since:
    Oct 2012

    Posted 12 Oct 2012 Link to this post

    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);

    <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="" />
                                <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%">
                                                Notes :
                                                <asp:TextBox ID="txtNote" TextMode="MultiLine" Width="200" Height="200" onblur runat="server"></asp:TextBox>
                                                <asp:Button ID="btnSaveNote" CommandArgument='<%# Container.DataItem("id")%>' Text="Save"
                                                    OnClick="btnSaveNote_Click" runat="server" />
                            <ItemStyle Width="15%" />

      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
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 15 Oct 2012 Link to this post

    Hi Muhammad,

    Here is the sample code that I tried to set focus in the textbox.
    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
    function SetFocusToTextBox(txt)
     var txtNote = $get(txt);

Back to Top