Scrolling to a specific control.

  • Thread starter Thread starter Mufasa
  • Start date Start date
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.
 
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
 
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.
 
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.
 
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.
 
[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();
 
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();
 
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();
 
[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...
 
Back
Top