For Programmers: Free Programming Magazines  


Home > Archive > ASP .NET > April 2008 > setting textbox focus at the end of the text









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author setting textbox focus at the end of the text
ton

2008-03-07, 8:20 am

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

ton

2008-04-17, 8:36 am

I found the solution:

in my VB PageLoad event

TextBox1.Attributes.Add("onfocus", "java script: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" <ton@nospam.nl> schreef in bericht
news:8601b$47d11c81$541eee8e$14256@cache
4.tilbu1.nb.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", "java script:__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


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2010 codecomments.com