Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Position page after postback

Status
Not open for further replies.

WMXTeam

Programmer
Oct 5, 2005
41
US
I have a very long form on the page. If the page does not validate, I want to reposition the page at the top of the form. I have a an anchor tag in the page, <a id="topofform">, but I am struggling with how to call in from the code. My page is written in C# and I am relatively new to .Net 2.0.

Thanks for your help.
 
register a startup script of js to navigate to the anchor. I believe the server side code is Page.RegisterClientScript(...). google "js anchor" to determine the appropiate js you need to render.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
probably already answered in post above, but

there is an attribute that can be added to the top of the aspx file, in the page attributes area.

MaintainScrollPositionOnPostback="false", or set to true if you do want to maintain position

(this is assuming that there is not text at the top of the page)

if you're using field validators (ie before postback to validate) there is toggle where u can set focus on that input.



 
Thank you for your help. I was able to get it to work through with the following:
Code:
String TopOfPageScript = "<script language='javascript'>window.location.href = '#topofform'</script>";
            Type cstype = this.GetType();
            //Page.RegisterStartupScript("TopOfpage", TopOfPageScript);
            ClientScript.RegisterStartupScript(cstype, "TopOfpage", TopOfPageScript, false);
I took a little while to figure out the RegisterStartupScript, but it is working.

I was interested in the comment above about field validators and the toggle to set focus. Would you be a little more specific?

Thanks for your help.
 
In some 2.0 validators, you can set the property SetFocusOnError = True. This will give focus to the control after validation fails. However, if you use a custom validator, that uses server side validation, that property does not set the postion of the page, only focus to the control. You would still have to scroll the page yourself.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top