Click here to Skip to main content
15,892,480 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
Hi I have a textbox and it's TextMode="MultiLine". I want set focus to end of this textbox when the page is refreshed.
In other way I want that the focus always sets in the end of the textbox.
thnx
Posted
Updated 26-Aug-11 18:21pm
v2

"Setting the focus to the end side of TextBox" is the exactly same thing as "setting the focus in any other place of TextBox". The notion of focus means keyboard focus and is related only to the control. Don't mix up focus and selection.

While you can use the method System.Web.UI.WebControls.TextBox.Focus, you cannot control text selection using this control. This is possible in WPF and System.Windows.Forms, not in APS.NET.

See http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.textbox.aspx[^].

—SA
 
Share this answer
 
Comments
Abhinav S 27-Aug-11 13:51pm    
Quite right. 5.
Sergey Alexandrovich Kryukov 27-Aug-11 21:35pm    
Thank you, Abhinav.
--SA
You can do this via some simple Javascript - see here[^].
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 27-Aug-11 21:37pm    
Oh, yes, this is a different story, but an interesting trick, good to know, my 5.
--SA
Abhinav S 28-Aug-11 1:21am    
Thank you SA.
instead of TextBox you can use Textarea and can achieve this functionality using javascrip

Have a look on that javascript getting and setting caret position in textarea/[^]
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 29-Aug-11 1:20am    
My 5.
--SA
nit_singh 29-Aug-11 2:26am    
Thanks SA
jiji2663 2-Sep-11 11:55am    
this don't work in i.e7
help pls
jiji2663 2-Sep-11 11:58am    
i use this code to run from server-side
ScriptManager.RegisterStartupScript(this, this.GetType(), "tmp2", " var t2 = document.getElementById('txtChat');t2.focus();t2.value = t2.value;", true);

but it's don't work in i.e7

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900