I tried to set a RadTextBox focus when the page loaded,but failed,why?

2 posts, 0 answers
  1. qin
    qin avatar
    1 posts
    Member since:
    Apr 2011

    Posted 29 Apr 2011 Link to this post

    I'm a Chinese ,My English is not good,sorry!

    I tried to set a RadTextBox focus when the page loaded,but failed,why?
    I used many of method
    1.RadTextBox.Focus();
    2.Page.SetFocus(RadTextBox.ClientID);
    3.page.SetFocus(RadTextBox).
    all failed.
    who can help me? thanks.
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 29 Apr 2011 Link to this post

    Hello Qin,

    You can achieve this either from server side or client side.
    If you want to achieve this from client side, one approach is to get the client object of the RadTextBox and set the focus either in pageLoad or from ClientEvents-OnLoad of the RadTextBox. Here is a sample code.

    Javascript:
    function pageLoad()
     {
          var radInput = $find("<%= RadInput1.ClientID %>");
          radInput.focus();
     }
    function onClientLoad(sender) // executes when loading the RadTextBox
     {
          sender.focus();
     }

    From server side you can try the following:
    C#:
    protected void Page_Load(object sender, EventArgs e)
       {
           RadInput1.Focus();
       }

    Corresponding aspx is:
    <telerik:RadTextBox ID="RadInput1" runat="server" ClientEvents-OnLoad="onClientLoad">
    </telerik:RadTextBox>

    Thanks,
    Shinu.
Back to Top