Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Adding JavaScript to focus on a section of the page after btn oncl

Reply
Thread Tools

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

 
 
=?Utf-8?B?UEs5?=
Guest
Posts: n/a
 
      03-06-2005
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
 
Reply With Quote
 
 
 
 
Damon Payne
Guest
Posts: n/a
 
      03-06-2005
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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



 
Reply With Quote
 
 
 
 
=?Utf-8?B?UEs5?=
Guest
Posts: n/a
 
      03-06-2005
There is a dropdown list (aspropdownList) 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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > 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

>
>
>

 
Reply With Quote
 
Damon Payne
Guest
Posts: n/a
 
      03-06-2005
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> There is a dropdown list (aspropdownList) 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" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed)...
> > > 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

> >
> >
> >



 
Reply With Quote
 
=?Utf-8?B?UEs5?=
Guest
Posts: n/a
 
      03-06-2005
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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > There is a dropdown list (aspropdownList) 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" <(E-Mail Removed)> wrote in message
> > > news:(E-Mail Removed)...
> > > > 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
> > >
> > >
> > >

>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DynamicTemplate with Delete btn inside a GridView gamesforums@hotmail.com ASP .Net 0 09-05-2008 01:55 PM
Cant access TreeView Node frm Btn Click event after populating frm another click even chandrajit_in ASP .Net 0 01-03-2008 10:45 AM
tkinter btn visual state with tkMessageBox jmdeschamps@gmail.com Python 4 08-20-2006 12:53 PM
Share folders btn 2 units =?Utf-8?B?S2V2aW4=?= Wireless Networking 2 09-16-2004 04:37 AM
Newbie: what's the difference btn ':=' and '<=' jk VHDL 8 01-23-2004 10:35 AM



Advertisments