What about Anchors (#) and ASP.NET?

L

Lars Netzel

Hello!

I have a LOOOOONG page with a bunch of panels that you can expand and
stuff.. and as you all know when you click on a servercontrol and get a
postback, it reloads and you end up at the top of the page ... is there
anyway to get the postback to add a #anchorname to the Address so I can keep
my location down in the page??

Regards
/Lars
 
A

Adam Barker

One way you can do this is inside your Page_Load event you can register some
startup javascript along the lines of document.location.hash = "mybookmark1"
which should navigate you to #mybookmark1 within your page. Register the
script block after check for IsPostBack() if you want to do this after some
user input/post back event.
 
B

Bobby Ryzhy

Hello!

I have a LOOOOONG page with a bunch of panels that you can expand and
stuff.. and as you all know when you click on a servercontrol and get a
postback, it reloads and you end up at the top of the page ... is there
anyway to get the postback to add a #anchorname to the Address so I can keep
my location down in the page??

Regards
/Lars

You can try some javascript -

C#
if (IsPostBack)
{
Page.Controls.Add(new LiteralControl("<script language = \"javascript\">"));
Page.Controls.Add(new LiteralControl(window.location="abc.aspx#123));
Page.Controls.Add(new LiteralControl("</script>"));
}


Bobby Ryzhy
bobby @ domain below
http://weekendtech.net
 
L

Lars Netzel

Thankx!:) Works Fine!

I need to add it in every single Event that postbacks of course but I guess
thats fine!

/Lars
 
J

Justin Beckwith

Inside of your page directives, the aspx page, use the
SmartNavigation=True directive.

Example: <%@ Page Language="vb" AutoEventWireup="false"
Codebehind="yourPage.aspx.vb" Inherits="yourProject.yourPage"
SmartNavigation="True"%>

This will do all of the dirty anchor work for you when postback is
caused by an asp.net control.

Happy Coding!
 

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

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top