By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,637 Members | 1,967 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,637 IT Pros & Developers. It's quick & easy.

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

P: n/a
PK9
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
Nov 19 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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" <PK*@discussions.microsoft.com> wrote in message
news:AF**********************************@microsof t.com...
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

Nov 19 '05 #2

P: n/a
PK9
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" <PK*@discussions.microsoft.com> wrote in message
news:AF**********************************@microsof t.com...
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


Nov 19 '05 #3

P: n/a
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" <PK*@discussions.microsoft.com> wrote in message
news:79**********************************@microsof t.com...
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" <PK*@discussions.microsoft.com> wrote in message
news:AF**********************************@microsof t.com...
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


Nov 19 '05 #4

P: n/a
PK9
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" <PK*@discussions.microsoft.com> wrote in message
news:79**********************************@microsof t.com...
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" <PK*@discussions.microsoft.com> wrote in message
news:AF**********************************@microsof t.com...
> 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


Nov 19 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.