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

Set Focus to Asp Textbox inside a Grid Template Column

5 Answers 195 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Anzar
Top achievements
Rank 2
Anzar asked on 17 Sep 2012, 06:07 AM
I have a Telerik Rad Grid With Template Columns. From one of this column i used  texbox as item template. And write onblur client side event to validate the input. On that event i need to set focus to that textbox.How?

5 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 17 Sep 2012, 06:22 AM
Hello,

Sorry, My below code snippet not fulfill your requirement.

<telerik:GridTemplateColumn>
                       <EditItemTemplate>
                           <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                       </EditItemTemplate>
                   </telerik:GridTemplateColumn>
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
    {
        if (e.Item.IsInEditMode && e.Item is GridEditableItem)
        {
            GridEditableItem item = e.Item as GridEditableItem;
            TextBox TextBox1 = item.FindControl("TextBox1") as TextBox;
            TextBox1.Focus();
        }
    }


Thanks,
Jayesh Goyani
0
Shinu
Top achievements
Rank 2
answered on 17 Sep 2012, 07:46 AM
Hi Anzar,

Please check the sample script I tried to validate a TextBox inside the Template Column in onblur event.

ASPX:
<telerik:GridTemplateColumn>
   <ItemTemplate>
         <asp:TextBox ID="TextBox1" runat="server" OnBlur="Onblur(this)"></asp:TextBox>
   </ItemTemplate>
</telerik:GridTemplateColumn>

Javascript:
function Onblur(TextBox)
{
    if (TextBox.value == "2") //checking for the value '2', if true set focus
    {
        window.setTimeout(function () { TextBox.focus(); }, 20);
    }
}

Thanks,
Shinu.
0
Anzar
Top achievements
Rank 2
answered on 17 Sep 2012, 12:18 PM
Hi Shinu,

 I tried your code. Its working properly. 

Thanks & Regards
Anzar.M
0
Anzar
Top achievements
Rank 2
answered on 17 Sep 2012, 12:26 PM
HI,

How to identify the the text  of the texxtbox is selected or not?

Thanks & Regards
Anzar.M
0
Gowtham
Top achievements
Rank 1
answered on 06 May 2014, 03:01 PM
Thanks to Jayesh Goyani's
working good.....
Tags
Grid
Asked by
Anzar
Top achievements
Rank 2
Answers by
Jayesh Goyani
Top achievements
Rank 2
Shinu
Top achievements
Rank 2
Anzar
Top achievements
Rank 2
Gowtham
Top achievements
Rank 1
Share this question
or