setting textbox focus at the end of the text

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ton

    setting textbox focus at the end of the text

    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.EventArg s) Handles Me.Load
    TextBox2.Attrib utes.Add("onKey Up", "javascript:__d oPostBack('" +
    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_TextCh anged(ByVal sender As Object, ByVal e As
    System.EventArg s)
    DbWebGrid2.Show Grid(dbRecordNE T.Session.dbTab leNum.cTableCli ent, , ,
    "where name like '%" & TextBox2.Text & "%'") 'shows the clients using the
    filter
    ScriptManager1. SetFocus(TextBo x2) '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

    #2
    Re: setting textbox focus at the end of the text

    I found the solution:

    in my VB PageLoad event

    TextBox1.Attrib utes.Add("onfoc us", "javascript:set SelectionRange( '"
    + "','')")


    on the top of my HTML code page:

    <script language="JavaS cript" type="text/javascript">
    function setSelectionRan ge()
    {
    var inputField = document.getEle mentById('TextB ox1');
    if (inputField != null && inputField.valu e.length 0)
    {
    if (inputField.cre ateTextRange)
    {
    var FieldRange = inputField.crea teTextRange();
    FieldRange.move Start('characte r',
    inputField.valu e.length);
    FieldRange.coll apse();
    FieldRange.sele ct();
    }
    }
    }
    </script>

    it works fine !



    "ton" <ton@nospam.nls chreef in bericht
    news:8601b$47d1 1c81$541eee8e$1 4256@cache4.til bu1.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.EventArg s) Handles Me.Load
    TextBox2.Attrib utes.Add("onKey Up", "javascript:__d oPostBack('" +
    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_TextCh anged(ByVal sender As Object, ByVal e As
    System.EventArg s)
    DbWebGrid2.Show Grid(dbRecordNE T.Session.dbTab leNum.cTableCli ent, ,
    , "where name like '%" & TextBox2.Text & "%'") 'shows the clients using
    the filter
    ScriptManager1. SetFocus(TextBo x2) '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

    Comment

    Working...