Adding JavaScript to focus on a section of the page after btn oncl

Discussion in 'ASP .Net' started by =?Utf-8?B?UEs5?=, Mar 6, 2005.

  1. I have a button at the top of my page that I have an onClick event handler
    for which makes some new controls (at the bottom of my page) visible. When
    the user clicks the button I make the new controls visible in the onclick
    event handler, but I do not know how to bring the focus to the bottom section
    of the page. So basically, when the user clicks the button, everything works
    correctly in the onclick (all controls are made visible), however when the
    page is displayed, the user would have to scroll down to the bottom to find
    the new controls.

    I'm looking for a way to bring the attention to the bottom section of the
    page where the new controls are. Remember that I have to use the onclick
    event handler to first make the controls visible. Any good ideas?

    --
    PK9
     
    =?Utf-8?B?UEs5?=, Mar 6, 2005
    #1
    1. Advertising

  2. =?Utf-8?B?UEs5?=

    Damon Payne Guest

    If there is a focusable field (like a text box) at the bottom of the page,
    you could do a RegisterStartupScript to put focus on that control, the
    browser should then scroll it to visible.


    --
    ------------------------------------------
    Damon Payne
    http://www.damonpayne.com

    "PK9" <> wrote in message
    news:...
    > I have a button at the top of my page that I have an onClick event handler
    > for which makes some new controls (at the bottom of my page) visible.

    When
    > the user clicks the button I make the new controls visible in the onclick
    > event handler, but I do not know how to bring the focus to the bottom

    section
    > of the page. So basically, when the user clicks the button, everything

    works
    > correctly in the onclick (all controls are made visible), however when the
    > page is displayed, the user would have to scroll down to the bottom to

    find
    > the new controls.
    >
    > I'm looking for a way to bring the attention to the bottom section of the
    > page where the new controls are. Remember that I have to use the onclick
    > event handler to first make the controls visible. Any good ideas?
    >
    > --
    > PK9
     
    Damon Payne, Mar 6, 2005
    #2
    1. Advertising

  3. Re: Adding JavaScript to focus on a section of the page after btn

    There is a dropdown list (asp:DropdownList) at the bottom of the page, but it
    is not even visible until the user clicks the button at the top of the page.

    When the user clicks the button, the onclick event handler (server side)
    makes a dropdownlist control at the bottom of the page visible, along with
    some other disabled fields. I want to be able to focus on that dropdownlist,
    or just that section of the page in general so the user doesn't have to
    scroll.

    Not sure how to accomplish this.

    "Damon Payne" wrote:

    > If there is a focusable field (like a text box) at the bottom of the page,
    > you could do a RegisterStartupScript to put focus on that control, the
    > browser should then scroll it to visible.
    >
    >
    > --
    > ------------------------------------------
    > Damon Payne
    > http://www.damonpayne.com
    >
    > "PK9" <> wrote in message
    > news:...
    > > I have a button at the top of my page that I have an onClick event handler
    > > for which makes some new controls (at the bottom of my page) visible.

    > When
    > > the user clicks the button I make the new controls visible in the onclick
    > > event handler, but I do not know how to bring the focus to the bottom

    > section
    > > of the page. So basically, when the user clicks the button, everything

    > works
    > > correctly in the onclick (all controls are made visible), however when the
    > > page is displayed, the user would have to scroll down to the bottom to

    > find
    > > the new controls.
    > >
    > > I'm looking for a way to bring the attention to the bottom section of the
    > > page where the new controls are. Remember that I have to use the onclick
    > > event handler to first make the controls visible. Any good ideas?
    > >
    > > --
    > > PK9

    >
    >
    >
     
    =?Utf-8?B?UEs5?=, Mar 6, 2005
    #3
  4. =?Utf-8?B?UEs5?=

    Damon Payne Guest

    Re: Adding JavaScript to focus on a section of the page after btn

    Yes, that makes sense.
    To put focus in that field afte the button click, you could put code
    something like this in your event handler. Assume your dropdown list is
    entitled "ddl"
    ....
    string script = "<script>document.getElementById('{0}').focus() </script>
    Page.RegisterStartupScript("focusDdl", string.Format(script, new
    object[]{ddl.ClientId});
    ....

    The page will run that javascript, and focus your field. If a field is
    focused the browser will scroll to where the field is visible.

    --
    ------------------------------------------
    Damon Payne
    http://www.damonpayne.com
    "PK9" <> wrote in message
    news:...
    > There is a dropdown list (asp:DropdownList) at the bottom of the page, but

    it
    > is not even visible until the user clicks the button at the top of the

    page.
    >
    > When the user clicks the button, the onclick event handler (server side)
    > makes a dropdownlist control at the bottom of the page visible, along with
    > some other disabled fields. I want to be able to focus on that

    dropdownlist,
    > or just that section of the page in general so the user doesn't have to
    > scroll.
    >
    > Not sure how to accomplish this.
    >
    > "Damon Payne" wrote:
    >
    > > If there is a focusable field (like a text box) at the bottom of the

    page,
    > > you could do a RegisterStartupScript to put focus on that control, the
    > > browser should then scroll it to visible.
    > >
    > >
    > > --
    > > ------------------------------------------
    > > Damon Payne
    > > http://www.damonpayne.com
    > >
    > > "PK9" <> wrote in message
    > > news:...
    > > > I have a button at the top of my page that I have an onClick event

    handler
    > > > for which makes some new controls (at the bottom of my page) visible.

    > > When
    > > > the user clicks the button I make the new controls visible in the

    onclick
    > > > event handler, but I do not know how to bring the focus to the bottom

    > > section
    > > > of the page. So basically, when the user clicks the button,

    everything
    > > works
    > > > correctly in the onclick (all controls are made visible), however when

    the
    > > > page is displayed, the user would have to scroll down to the bottom to

    > > find
    > > > the new controls.
    > > >
    > > > I'm looking for a way to bring the attention to the bottom section of

    the
    > > > page where the new controls are. Remember that I have to use the

    onclick
    > > > event handler to first make the controls visible. Any good ideas?
    > > >
    > > > --
    > > > PK9

    > >
    > >
    > >
     
    Damon Payne, Mar 6, 2005
    #4
  5. Re: Adding JavaScript to focus on a section of the page after btn

    Thanks Damon! That works perfectly. I also added a check in my event
    handler to see if the script was already registered. I assume I should do
    this, if not please advise.

    if (!IsStartupScriptRegistered("focuslstShortTitles"))
    {
    string script = "<script> document.getElementById('{0}').focus() </script>";
    Page.RegisterStartupScript("focuslstShortTitles", string.Format(script,
    new object[]{lstShortTitles.ClientID}));
    }

    Paul

    "Damon Payne" wrote:

    > Yes, that makes sense.
    > To put focus in that field afte the button click, you could put code
    > something like this in your event handler. Assume your dropdown list is
    > entitled "ddl"
    > ....
    > string script = "<script>document.getElementById('{0}').focus() </script>
    > Page.RegisterStartupScript("focusDdl", string.Format(script, new
    > object[]{ddl.ClientId});
    > ....
    >
    > The page will run that javascript, and focus your field. If a field is
    > focused the browser will scroll to where the field is visible.
    >
    > --
    > ------------------------------------------
    > Damon Payne
    > http://www.damonpayne.com
    > "PK9" <> wrote in message
    > news:...
    > > There is a dropdown list (asp:DropdownList) at the bottom of the page, but

    > it
    > > is not even visible until the user clicks the button at the top of the

    > page.
    > >
    > > When the user clicks the button, the onclick event handler (server side)
    > > makes a dropdownlist control at the bottom of the page visible, along with
    > > some other disabled fields. I want to be able to focus on that

    > dropdownlist,
    > > or just that section of the page in general so the user doesn't have to
    > > scroll.
    > >
    > > Not sure how to accomplish this.
    > >
    > > "Damon Payne" wrote:
    > >
    > > > If there is a focusable field (like a text box) at the bottom of the

    > page,
    > > > you could do a RegisterStartupScript to put focus on that control, the
    > > > browser should then scroll it to visible.
    > > >
    > > >
    > > > --
    > > > ------------------------------------------
    > > > Damon Payne
    > > > http://www.damonpayne.com
    > > >
    > > > "PK9" <> wrote in message
    > > > news:...
    > > > > I have a button at the top of my page that I have an onClick event

    > handler
    > > > > for which makes some new controls (at the bottom of my page) visible.
    > > > When
    > > > > the user clicks the button I make the new controls visible in the

    > onclick
    > > > > event handler, but I do not know how to bring the focus to the bottom
    > > > section
    > > > > of the page. So basically, when the user clicks the button,

    > everything
    > > > works
    > > > > correctly in the onclick (all controls are made visible), however when

    > the
    > > > > page is displayed, the user would have to scroll down to the bottom to
    > > > find
    > > > > the new controls.
    > > > >
    > > > > I'm looking for a way to bring the attention to the bottom section of

    > the
    > > > > page where the new controls are. Remember that I have to use the

    > onclick
    > > > > event handler to first make the controls visible. Any good ideas?
    > > > >
    > > > > --
    > > > > PK9
    > > >
    > > >
    > > >

    >
    >
    >
     
    =?Utf-8?B?UEs5?=, Mar 6, 2005
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. jk
    Replies:
    8
    Views:
    560
    David Brown
    Jan 23, 2004
  2. Replies:
    4
    Views:
    385
  3. chandrajit_in
    Replies:
    0
    Views:
    1,703
    chandrajit_in
    Jan 3, 2008
  4. Replies:
    0
    Views:
    274
  5. Roger
    Replies:
    3
    Views:
    338
Loading...

Share This Page