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

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

1 Answer 190 Views
Input
This is a migrated thread and some comments may be shown as answers.
qin
Top achievements
Rank 1
qin asked on 29 Apr 2011, 09:02 AM
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.

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 29 Apr 2011, 10:10 AM
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.
Tags
Input
Asked by
qin
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or