Set Focus Problem

Last post 08-28-2008 11:12 PM by chetan.sarode. 4 replies.

Sort Posts:

  • Set Focus Problem

    08-28-2008, 11:29 AM
    • Member
      point Member
    • MissSara
    • Member since 08-28-2008, 3:11 PM
    • Posts 2
    I'm not sure if this the right place for this, let me know if there's somewhere else I should post it..I'm having problems using Page.SetFocus with an AJAX enabled Web Application. I'm using VS 2005 and AJAX 2.0. On my page I'm using the RoundedCornersExtender and ModalPopupExtender.For a brief moment when the page loads, the cursor is set to the appropriate textbox, but after the final load, the focus is lost.I tried using javascript, VB.NET Page.SetFocus, and even Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(with a function call to set the focus) to catch when ajax was done loading. Using the pageLoaded event worked great - but I have to use a delay.. but if the user is quicker than the delay the focus isn't given a chance to render.

     Is there any way around this time delay? or is there a better way to set focus?

    Thanks,
    Sara

     

  • Re: Set Focus Problem

    08-28-2008, 1:32 PM

     I have ran into the SetFocus problem..(not exactly the same scenario, but it was with Ajax..)

    I used, 

    ScriptManager scrMgr = ScriptManager.GetCurrent(this.Page);

    scrMgr.SetFocus(this.textbox1.ClientID);

     worked for me!..

     HTH

    http://dotnet-tips.blogspot.com/
  • Re: Set Focus Problem

    08-28-2008, 2:25 PM
    • Member
      point Member
    • MissSara
    • Member since 08-28-2008, 3:11 PM
    • Posts 2

    I tried that.. didn't work :( Thanks though!

  • Re: Set Focus Problem

    08-28-2008, 8:08 PM
    • Star
      8,978 point Star
    • dwhite
    • Member since 02-08-2007, 2:25 PM
    • Bristol, CT
    • Posts 1,422

    Did you try calling the code from the event window.onload on the client side?

    For example:

    window.onload = _onPageLoad;

    function _onPageLoad() {
      // TODO: Set focus
    }

    PageLoad should fire after the page has fully loaded.

    Hope this helps,
    -Damien

    Visoft, Inc - Home | Blogs

    Latest Blog Post: Silverlight DataBinding Bug
  • Re: Set Focus Problem

    08-28-2008, 11:12 PM
    Answer

    Sets the browser focus to the specified control

    http://www.asp.net/AJAX/Documentation/Live/mref/O_T_System_Web_UI_ScriptManager_SetFocus.aspx

    http://gmamaladze.googlepages.com/maintainfocusbetweenpostbacksalsoinasp.n

    You can use the following code to set the focus:
     

    ScriptManager sm = ScriptManager.GetCurrent(this);
    sm.SetFocus(myTextBox);

    To set focus and select text of a you have to use the following:
     

    ScriptManager.RegisterStartupScript(this, this.GetType(), "selectAndFocus", "$get('" + myTextBox.ClientID + "').focus();$get('" + myTextBox.ClientID + "').select();", true);
    http://forums.asp.net/t/1099345.aspx
    http://forums.asp.net/t/1199709.aspx
    Chetan Sarode
    Software Engineer,
    Approva Systems Pvt Ltd,
    Pune, India.
Page 1 of 1 (5 items)