469,613 Members | 1,299 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,613 developers. It's quick & easy.

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

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
4 2971
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
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
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
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.

Similar topics

3 posts views Thread by annon | last post: by
reply views Thread by Luis Esteban Valencia | last post: by
3 posts views Thread by TCORDON | last post: by
27 posts views Thread by Chris | last post: by
1 post views Thread by The Eclectic Electric | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.