Scrolling to a specific control.

M

Mufasa

I have a control on a page that appears when there's something somebody
needs to enter. No problem - part of a panel and when they need to enter
into it, I set the focus for the control. Problem is, it's not on the page.
How can I get the control to be on the page when the page reloads?

TIA - Jeff.
 
D

David Wier

If you are creating the control dynamically, make sure it gets created each
time the page reloads
If you're talking visiblity, then, just make sure the control or panel in
which it's contained is visible, based on the event handler necessary for
this.

David Wier
http://aspnet101.com
http://iWritePro.com - One click PDF, convert .doc/.rtf/.txt to HTML with no
bloated markup
 
M

Mufasa

OK everybody - let me try this again:

I've got a control that isn't visible all the time - it's in a panel. When
the user clicks a button, I make the panel visible and I want to scroll to a
control on the panel. I can set the focus to the control but that doesn't
scroll to the control. I've tried setting
Page.MaintainScrollPositionOnPostBack = true; but that just scrolls back to
the place it was before - not to the control I need it to go to.

Any ideas?

TIA - Jeff.
 
G

George Ter-Saakov

Use Javascript's function .focus();. It will scroll control into visible
portion of the screen.

Something like this
var obj = document.getElementById('myid');
obj.focus();


George.
 
M

Mufasa

Great. Thank you. When I have a .Net control, the name get's changed as the
page is loaded so that something that is tbPersonsName becomes something
weird like tbPersonsName_ctl100. If I'm going to write javascript code to
find that control, I need to know the name of the control as it actually
appears on the page. How do I find out the name on the page rather than what
I've called it in code?

TIA - Jeff.
 
M

Mark Rae [MVP]

[top-posting corrected]
Great. Thank you. When I have a .Net control, the name get's changed as
the page is loaded so that something that is tbPersonsName becomes
something weird like tbPersonsName_ctl100. If I'm going to write
javascript code to find that control, I need to know the name of the
control as it actually appears on the page. How do I find out the name on
the page rather than what I've called it in code?

document.getElementById('<%=MyControl.ClientID%>').focus();
 
M

Mufasa

I don't think that helps me. I still don't know the actual name of the
control since it's been changed by .Net.

Mark Rae said:
[top-posting corrected]
Great. Thank you. When I have a .Net control, the name get's changed as
the page is loaded so that something that is tbPersonsName becomes
something weird like tbPersonsName_ctl100. If I'm going to write
javascript code to find that control, I need to know the name of the
control as it actually appears on the page. How do I find out the name on
the page rather than what I've called it in code?

document.getElementById('<%=MyControl.ClientID%>').focus();
 
G

George Ter-Saakov

That is what <%=MyControl.ClientID%> for.
It will output the actual Control Id.
Obviously MyControl is your controls' name. ClientID is a property any .NET
control have

George.



Mufasa said:
I don't think that helps me. I still don't know the actual name of the
control since it's been changed by .Net.

Mark Rae said:
[top-posting corrected]
Great. Thank you. When I have a .Net control, the name get's changed as
the page is loaded so that something that is tbPersonsName becomes
something weird like tbPersonsName_ctl100. If I'm going to write
javascript code to find that control, I need to know the name of the
control as it actually appears on the page. How do I find out the name
on the page rather than what I've called it in code?

document.getElementById('<%=MyControl.ClientID%>').focus();
 
M

Mark Rae [MVP]

[top-posting corrected again]
I don't think that helps me. I still don't know the actual name of the
control since it's been changed by .Net.

That's what <%=MyControl.ClientID%> is for...
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top