Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 21st, 2007, 01:50 PM
Registered User
 
Join Date: May 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Passing a Session Variable in a href

Hi all,

This is my first post, I hope someone out there can help. For the life of me, I can't figure out what I'm missing to include the value of a session variable in a <a href> tag.

Here's the code in question:
<% if Session("SourceOther") = "" Then %>
    <a href="prescreening.aspx" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image13','','images/ov_qualify2.jpg',1)"><img alt="Do you or a loved one qualify? Find out now" src="images/ov_qualify1.jpg" width="218" height="42" id="Img2" name="Image13" border="0"></a>
    <% else %>
    <a href="<%prescreening.aspx?s= & Session("SourceOther")%>" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image13','','images/ov_qualify2.jpg',1)"><img alt="Do you or a loved one qualify? Find out now" src="images/ov_qualify1.jpg" width="218" height="42" id="Img3" name="Image13" border="0"></a>
<% end if %>

I've tried different combinations of the href="<%prescreening.aspx?s= & Session("SourceOther")%>" line, but to no avail. Many thanks for the help.

-Orcabelle

 
Old May 21st, 2007, 03:05 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

O.o While it is possible to code ASP.NET like this, I am not sure why you would want to. At first glance I thought you had posted Classic ASP code in the .NET forum that, however, doesn't seem to be the case.

Anyway the problem in your code is this:
<a href="<%prescreening.aspx?s= & Session("SourceOther")%>"

it should be:
<a href='prescreening.aspx?s=<%=Session("SourceOther" )%>'>foo</a>

Also, you could make this a lot more readable by doing it in a code behind (for the sake of simplicity I am going to omit your Javascript)

page.aspx
<asp:HyperLink id="hl" runat=server" Text="foo" />

page.vb
If Session("SourceOther") = "" Then
    h1.NavigateUrl = "prescreening.aspx"
Else
    h1.NavigateUrl = "prescreening.aspx?s=" & Session("SourceOther")
End If

Much nicer ^^


================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========
 
Old May 21st, 2007, 03:16 PM
Registered User
 
Join Date: May 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Awesome! It works. Thank you so much for your speedy reply. As for the code behind, that's where I was headed next. Thank you again.

-Orcabelle
 
Old May 21st, 2007, 03:41 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Glad you got it working.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 8, href and HRef (p. 285) roman BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 2 June 16th, 2008 10:40 AM
passing params on an href function call geogomez Javascript How-To 1 November 29th, 2005 06:26 AM
Passing variable to a public variable Hudson40 Access VBA 2 February 25th, 2005 06:23 AM
Passing Session Variable quinn Classic ASP Basics 1 December 11th, 2003 03:44 PM
passing variable gumgak Classic ASP Databases 13 June 29th, 2003 09:13 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.