Which control had focus before postback?

Ask a Question related to ASP.NET General, Design and Development.

  1. #1

    Default 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 (smartnavigation doesn't
    do the trick).

    Thanks, Marco


    Marco Liedekerken Guest

  2. Similar Questions and Discussions

    1. Taking focus from a control
      In my app, I have a DataGrid, and when a row is double-clicked, a new view is put up showing the data. I also add eventListeners to the stage for...
    2. Setting Focus in a User Control
      I have an editable datagrid as part of a usercontrol. When I click the Edit button, I wish for focus to be set on the first control, a...
    3. How control which button has focus [ENTER]
      Hello, I'm facing a problem with the behavior of the key while editing items in a datagrid. I would like to make sure that the cancel button is...
    4. focus/lost focus of custom control
      Hi new to .NET and have a question. What I want to do if have a custome control (contains a table grid of text boxes) and multiple instances...
    5. Control focus
      Hi guys, How to Focus a TextBox on page load? I have this function: public static void FocusControl(Page pagina, WebControl control) {...
  3. #2

    Default 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:
    > 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 (smartnavigation doesn't
    > do the trick).
    >
    > Thanks, Marco
    >
    >
    Kairi Zikpin Guest

  4. #3

    Default 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(WebControl wc)

    {

    StringBuilder sScript = new StringBuilder("");

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

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

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

    Page.RegisterStartupScript("Focus", sScript.ToString());

    }

    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.1070105@netscape.net...
    > 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:
    > > 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 (smartnavigation
    doesn't
    > > do the trick).
    > >
    > > Thanks, Marco
    > >
    > >
    >

    Jeff Siver Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139