Set Focus to Asp Textbox inside a Grid Template Column

6 posts, 0 answers
  1. Anzar
    Anzar avatar
    62 posts
    Member since:
    Sep 2012

    Posted 17 Sep 2012 Link to this post

    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?
  2. Jayesh Goyani
    Jayesh Goyani avatar
    2733 posts
    Member since:
    May 2010

    Posted 17 Sep 2012 Link to this post

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

    Posted 17 Sep 2012 Link to this post

    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.
  4. Anzar
    Anzar avatar
    62 posts
    Member since:
    Sep 2012

    Posted 17 Sep 2012 Link to this post

    Hi Shinu,

     I tried your code. Its working properly. 

    Thanks & Regards
    Anzar.M
  5. Anzar
    Anzar avatar
    62 posts
    Member since:
    Sep 2012

    Posted 17 Sep 2012 Link to this post

    HI,

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

    Thanks & Regards
    Anzar.M
  6. Gowtham
    Gowtham avatar
    7 posts
    Member since:
    Jun 2013

    Posted 06 May 2014 in reply to Jayesh Goyani Link to this post

    Thanks to Jayesh Goyani's
    working good.....
Back to Top