By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,694 Members | 1,302 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,694 IT Pros & Developers. It's quick & easy.

setting textbox focus at the end of the text

P: n/a
ton
Hi,

I'm using Ajax to seach direct in a gridview. It works fine. I even keep the
focus on the input text box. Here is my code:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
TextBox2.Attributes.Add("onKeyUp", "javascript:__doPostBack('" +
TextBox2.ID + "','')")
TextBox2.Focus() 'the initial focus in de load event of the page

and when firing the postback after the key up I got this function working:

Protected Sub TextBox2_TextChanged(ByVal sender As Object, ByVal e As
System.EventArgs)
DbWebGrid2.ShowGrid(dbRecordNET.Session.dbTableNum .cTableClient, , ,
"where name like '%" & TextBox2.Text & "%'") 'shows the clients using the
filter
ScriptManager1.SetFocus(TextBox2) 'this keeps the focus, BUT ON THE
FIRST CHARACTER
End Sub
How can I keep the cursor to the end of the textbox, so user can keep on
typing to refine their search

thanks

Ton

Mar 7 '08 #1
Share this Question
Share on Google+
1 Reply


P: n/a
ton
I found the solution:

in my VB PageLoad event

TextBox1.Attributes.Add("onfocus", "javascript:setSelectionRange('"
+ "','')")
on the top of my HTML code page:

<script language="JavaScript" type="text/javascript">
function setSelectionRange()
{
var inputField = document.getElementById('TextBox1');
if (inputField != null && inputField.value.length 0)
{
if (inputField.createTextRange)
{
var FieldRange = inputField.createTextRange();
FieldRange.moveStart('character',
inputField.value.length);
FieldRange.collapse();
FieldRange.select();
}
}
}
</script>

it works fine !

"ton" <to*@nospam.nlschreef in bericht
news:86***************************@cache4.tilbu1.n b.home.nl...
Hi,

I'm using Ajax to seach direct in a gridview. It works fine. I even keep
the focus on the input text box. Here is my code:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
TextBox2.Attributes.Add("onKeyUp", "javascript:__doPostBack('" +
TextBox2.ID + "','')")
TextBox2.Focus() 'the initial focus in de load event of the page

and when firing the postback after the key up I got this function working:

Protected Sub TextBox2_TextChanged(ByVal sender As Object, ByVal e As
System.EventArgs)
DbWebGrid2.ShowGrid(dbRecordNET.Session.dbTableNum .cTableClient, ,
, "where name like '%" & TextBox2.Text & "%'") 'shows the clients using
the filter
ScriptManager1.SetFocus(TextBox2) 'this keeps the focus, BUT ON THE
FIRST CHARACTER
End Sub
How can I keep the cursor to the end of the textbox, so user can keep on
typing to refine their search

thanks

Ton
Jun 27 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.