Which control had focus before postback?

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

    Which control had focus before postback?

    Hi,

    Is it possible to retrieve the control that had the focus when the page was
    posted back?

    Because the focus is lost when a postback occurs I want to manually set the
    focus to the control that previously had the focus (smartnavigatio n doesn't
    do the trick).

    Thanks, Marco


  • Kairi Zikpin

    #2
    Re: Which control had focus before postback?

    use javascript
    once the page hits the browser, .net is no longer at play

    eg, object.onfocus( ), set some hidden field to the control's name
    once the page is back to the browser, use javascript again to set focus

    it's a lot of work but that's the only way i've found that works. just
    be careful about objects no longer being on the form or being disabled.

    Marco Liedekerken wrote:[color=blue]
    > Hi,
    >
    > Is it possible to retrieve the control that had the focus when the page was
    > posted back?
    >
    > Because the focus is lost when a postback occurs I want to manually set the
    > focus to the control that previously had the focus (smartnavigatio n doesn't
    > do the trick).
    >
    > Thanks, Marco
    >
    >[/color]

    Comment

    • Jeff Siver

      #3
      Re: Which control had focus before postback?

      Here's a C# function you can call to have a page set focus when the page is
      displayed:

      protected void SetFocus(WebCon trol wc)

      {

      StringBuilder sScript = new StringBuilder(" ");

      sScript.Append( "<script language='javas cript'>");

      sScript.Append( " document.getEle mentById('" + wc.UniqueID + "').focus() ");

      sScript.Append( "</script>");

      Page.RegisterSt artupScript("Fo cus", sScript.ToStrin g());

      }

      All you need to do is call this function before posting the page. Should do
      what you need.

      "Kairi Zikpin" <zikkai.nospam. @netscape.net> wrote in message
      news:3F0199E1.1 070105@netscape .net...[color=blue]
      > use javascript
      > once the page hits the browser, .net is no longer at play
      >
      > eg, object.onfocus( ), set some hidden field to the control's name
      > once the page is back to the browser, use javascript again to set focus
      >
      > it's a lot of work but that's the only way i've found that works. just
      > be careful about objects no longer being on the form or being disabled.
      >
      > Marco Liedekerken wrote:[color=green]
      > > Hi,
      > >
      > > Is it possible to retrieve the control that had the focus when the page[/color][/color]
      was[color=blue][color=green]
      > > posted back?
      > >
      > > Because the focus is lost when a postback occurs I want to manually set[/color][/color]
      the[color=blue][color=green]
      > > focus to the control that previously had the focus (smartnavigatio n[/color][/color]
      doesn't[color=blue][color=green]
      > > do the trick).
      > >
      > > Thanks, Marco
      > >
      > >[/color]
      >[/color]


      Comment

      Working...