Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old May 21st, 2007, 01:50 PM
Registered User
 
Join Date: May 2007
Location: Silver Spring, MD, USA.
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

Reply With Quote
  #2 (permalink)  
Old May 21st, 2007, 03:05 PM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
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
================================================== =========
Reply With Quote
  #3 (permalink)  
Old May 21st, 2007, 03:16 PM
Registered User
 
Join Date: May 2007
Location: Silver Spring, MD, USA.
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
Reply With Quote
  #4 (permalink)  
Old May 21st, 2007, 03:41 PM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
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
================================================== =========
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 11:58 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.