Set focus on textbox after AutoPostback??

Last post 09-11-2007 12:30 PM by gdl. 12 replies.

Sort Posts:

  • Set focus on textbox after AutoPostback??

    09-04-2007, 7:53 AM
    • Loading...
    • KJAK
    • Joined on 03-14-2006, 4:07 PM
    • Posts 176

    I have a few textboxes inside an UpdatePanel that are used to calculate values in some labels. Each time a user exits a textbox, the server needs to make some calculations and change the values on the labels. After it does the calculations and comes back, I would like the next textbox to have focus. I would like to make it so that the user can tab between textboxes. Currently, when I leave a textbox, everything loses focus and I have to select the next textbox myself. I have tried to use a variable to set the focus in the Page_load, but it doesn't seem to help. I am using Master Pages, that might be a cause of the problem, but I am not sure.

    Any help?

     

    Respect to the community...

    KJAK
  • Re: Set focus on textbox after AutoPostback??

    09-04-2007, 8:22 AM
    • Loading...
    • sujitm
    • Joined on 05-23-2007, 9:01 AM
    • Pune
    • Posts 506

    Use the SetFocus method of page and pass the textbox to the method.

    - Sujit

    Dont forget to click "Mark as Answer" on the post that helped you.
    This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.
  • Re: Set focus on textbox after AutoPostback??

    09-04-2007, 9:30 AM
    • Loading...
    • KJAK
    • Joined on 03-14-2006, 4:07 PM
    • Posts 176

    sujitm:

    Use the SetFocus method of page and pass the textbox to the method.

    Okay, when the cursor leaves each textbox, I have a Session("TextBox") variable that indicates which TextBox should be next to have focus.

    On the page load, I select case the Session variable and it detects and reads the Me.SetFocus("TextBox1") code, however it does not actually set the focus on the page.

    More Thoughts?

    Respect to the community...

    KJAK
  • Re: Set focus on textbox after AutoPostback??

    09-04-2007, 2:41 PM
    • Loading...
    • gt1329a
    • Joined on 06-23-2002, 8:53 PM
    • Atlanta
    • Posts 1,749

    For partial postbacks, use the SetFocus() method of the ScriptManager control on your page. 

  • Re: Set focus on textbox after AutoPostback??

    09-04-2007, 11:54 PM
    Answer

    Use

     this.ScropManager.SetFocus(textBox.ClientId)

    Let me know if this helpful to you

    Chetan Sarode
    Software Engineer,
    Approva Systems Pvt Ltd,
    Pune, India.
  • Re: Set focus on textbox after AutoPostback??

    09-05-2007, 2:14 AM
    • Loading...
    • sujitm
    • Joined on 05-23-2007, 9:01 AM
    • Pune
    • Posts 506

    In that case use ScriptManager.SetFocus method with the ID of your control.

    - Sujit

    Dont forget to click "Mark as Answer" on the post that helped you.
    This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.
  • Re: Set focus on textbox after AutoPostback??

    09-05-2007, 7:25 AM
    • Loading...
    • KJAK
    • Joined on 03-14-2006, 4:07 PM
    • Posts 176

    The scriptmanager resides on the Master page. How can I reference the scriptmanager from a content page?

    Respect to the community...

    KJAK
    Filed under:
  • Re: Set focus on textbox after AutoPostback??

    09-05-2007, 8:30 AM
    • Loading...
    • sujitm
    • Joined on 05-23-2007, 9:01 AM
    • Pune
    • Posts 506
    1. Use <Master> page directive in the ASPX page and set the VirtualPath and TypeName attribute of the MasterPage correctly.
    2. Define a public property in the master file say. ScriptManager etc.
    3. Now, you should be able to access the ScriptManager property in the content pages.
    - Sujit

    Dont forget to click "Mark as Answer" on the post that helped you.
    This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.
  • Re: Set focus on textbox after AutoPostback??

    09-05-2007, 12:18 PM
    Answer
    • Loading...
    • gt1329a
    • Joined on 06-23-2002, 8:53 PM
    • Atlanta
    • Posts 1,749
    You can use ScriptManager.GetCurrent() to find and get a reference to the page's ScriptManager.
  • Re: Set focus on textbox after AutoPostback??

    09-05-2007, 5:55 PM
    • Loading...
    • FrenchiInLA
    • Joined on 03-30-2005, 8:00 PM
    • Huntington Beach, CA
    • Posts 80
    ScriptManager sm = ScriptManager.GetCurrent(Page);

    sm.SetFocus(Control);

  • Re: Set focus on textbox after AutoPostback??

    09-05-2007, 11:47 PM

    ScriptManager scriptManager = ScriptManager.GetCurrent(Page);

    scriptManger.SetFocus(textBox.ClietId); 

    Chetan Sarode
    Software Engineer,
    Approva Systems Pvt Ltd,
    Pune, India.
  • Re: Set focus on textbox after AutoPostback??

    09-06-2007, 12:48 AM
    • Loading...
    • gt1329a
    • Joined on 06-23-2002, 8:53 PM
    • Atlanta
    • Posts 1,749

    chetan.sarode:

    ScriptManager scriptManager = ScriptManager.GetCurrent(Page);

    scriptManger.SetFocus(textBox.ClietId); 

     

    ScriptManager.SetFocus() requires a parameter with type of Control, not a control's client ID.  The previously posted method is the correct way to do it. 

  • Re: Set focus on textbox after AutoPostback??

    09-11-2007, 12:30 PM
    • Loading...
    • gdl
    • Joined on 06-21-2002, 8:10 PM
    • Austin, TX
    • Posts 91

    chetan.sarode:

    Use

     this.ScropManager.SetFocus(textBox.ClientId)

    Let me know if this helpful to you

     

    The above code worked perfectly for me since my control is in the content page.

     

    Ricardo D. Sanchez
    GDL Technologies
    www.gdltec.net

    Please remember to click "Mark as Answer" on this post if it helped you.
Page 1 of 1 (13 items)
Microsoft Communities
Page view counter