WebForm scroll position after PostBack

  • Thread starter Thread starter Steve Covert
  • Start date Start date
S

Steve Covert

In the case of a long Webform, when a PostBack event occurrs, is there a
technique to position the Form at where it was when the event fired?

Similar to using an anchor tag in html to go to a specific location in a
page.

Thanks!
 
You can render html to the browser that uses the Anchor
tag to go to a specific location.
the following code writes out an <A> tag to the browser
(you'll need to insert it in the appropriate place), and
runs a script that positions the form at that spot.

[C#]
string Arg = Request.Form["__EVENTARGUMENT"];
n.Text += "<A name='#" + Arg + "'></A>";
string script = "<SCRIPT
language='javascript'>location.href='#" + Arg
+ "';</SCRIPT>";
Page.RegisterStartupScript("posForm",script);

You don't need to use Request.Form["__EVENTARGUMENT"],
any string will do here but it can help if you're trying
to determine which event that caused the postback

alex
 
Back
Top