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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Redirecting to anchors on ASP pages

Status
Not open for further replies.

GaryCam

Programmer
Dec 16, 2003
69
US
I know nothing about ASP so any help is greatly appreciated.

I have inherited an ASP page which contains a product ordering form. After a QTY is entered and the form is submitted using a numbered submit button, a second ASP form processes the data. At the foot of this second ASP page a Response.Redirect statement returns the user to the ordering form on the initial page. My problem is that the redirect always goes back to the top of the firstpage.asp instead of going to the anchors. Here's the code in question:

Code:
    If(Request.Form("whichSubmitButton") = "1")Then
        Response.Redirect "firstpage.asp#anchor1"
    ElseIf(Request.Form("whichSubmitButton") = "2")Then
        Response.Redirect "firstpage.asp#anchor2"
    Else
        Response.Redirect "firstpage.asp#anchor3"
    End If

Is this syntax incorrect? Or could it be because it's redirecting to anchors that are in a scrolling <div> on firstpage.asp. I.e., it's returning to the page but can't scroll to the anchor itself?

Any help (especially snippets of code) are welcomed and most appreciated.

~ Gary
 
I'm sure someone will correct me if I'm wrong on this....

I *think* what is happening is this:

The Anchor function is a product of the web browser. It's probably trying to go to the anchor before the page is built.

You can *try* putting a
Code:
<% Response.Buffer=True %>

at the top of your code, and see if that helps. Otherwise, you're going to have to find a way to wait until the page is completely built, then jump to the anchor.

One way to do that would be to pass
Code:
Response.Redirect "firstpage.asp?anchor=2"

Then, use a piece of javascript to jump to the anchor when the page is completely loaded... put it as the last statement in your ASP code...

Code:
<script language=Javascript>
document.location = "#<%=anchor%>"
</script>

Something like that perhaps? Then, the page would finish loading from ASP, then a little javascript to relocate to the anchor that was passed.



Just my 2¢

"What the captain doesn't realize is that we've secretly replaced his Dilithium Crystals with new Folger's Crystals."

--Greg
 
Thanks, Greg, but those solutions don't work. I think your approach may be the solution but ASP will not accept the following line:

<script language=Javascript>

Any other suggestions?

~ Gary
 
Oh... ASP will do that...

Well, in your .asp page, you don't include the

<script language=javascript> inside the <% %>

Just put it at the bottom of the page, after your final %>



Just my 2¢

"What the captain doesn't realize is that we've secretly replaced his Dilithium Crystals with new Folger's Crystals."

--Greg
 
I made the modification but it still redirects only to the top of firstpage.asp. In fact, on firstpage.asp I also have an image map that provides links to those same anchors: #anchor1, #anchor2 and #anchor3. That image map doesn't work either.

~ Gary
 
What if you type the anchors directly into the address bar? Does it work then?

Normally if it's redirecting to the top of the page, the anchor is mis-named or not found or something....



Just my 2¢

"What the captain doesn't realize is that we've secretly replaced his Dilithium Crystals with new Folger's Crystals."

--Greg
 
Thanks, Greg. I got it to go to anchors. The problem had to do with the anchors being outside some CSS Divs (or something like that, anyway it works now).

Now that I can direct one ASP page to return to an anchor on another page, I can't seem to get that ASP page to recognize which submit button was the sender. I'd like the ASP page to return to an anchor associated with the submit button that sent it.

I'll start a new thread for this.

Thanks again,
Gary
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top