Solved

Session variables included in quotes

Posted on 2013-05-16
6
233 Views
Last Modified: 2013-07-09
Hi all,

I have a hopefully relatively quick question.

In javascript how can I used a session variable included in quotes?

For instance, I need something like:

"<%# Session["Test"] %>"

I found I cannot use:

'<%# Session["Test"] %>'

And ASP.NET chokes on an invalid character if I do:

"<%# Session['Test'] %>"

"Test" can include text which has embedded quotes both single and doube already.

This appears to work:

"<%# Session["Test"] %>"

But the Test word is black because the preceding " is closing it off.

Any suggestions on how to work with the Session quotes within quotes?

Any assistance would be greatly appreciated.

Thanks
0
Comment
Question by:davism
  • 3
  • 2
6 Comments
 
LVL 34

Expert Comment

by:Paul MacDonald
ID: 39172343
Why do you need the surrounding quotes at all?  Why not just:
   <%# Session['Test'] %>

Are you using it as a literal?  Can you post the context in which you're trying to get it to work?
0
 
LVL 22

Expert Comment

by:Mrunal
ID: 39172346
Try this one:

"<%= Session['Test'] %>"
0
 
LVL 1

Author Comment

by:davism
ID: 39172374
mroonal, yep I would think that too but I got an error on an invalid statement in asp.net when I did that.

paulmacd, I'm trying to use it in an IF statement.

if ( "<%# Session["Test"] %>" == "" )
{  

Again, the above works and is doing everything as expected when the page runs BUT in the IDE it's showing the Test as black.
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
LVL 34

Accepted Solution

by:
Paul MacDonald earned 250 total points
ID: 39172455
Well in fairness, that is pretty convoluted.  If it works, and the IDE doesn't complain, I wouldn't worry about it.
0
 
LVL 1

Author Comment

by:davism
ID: 39172597
Yeah, I'm with you on that. It just didn't make sense why it did. And in all honesty, I really didn't think twice about it when I did it.

I was just wondering which is why I posted the question as to how it would've/should've been done.

So, any thoughts/ideas would be great.
0
 
LVL 1

Author Closing Comment

by:davism
ID: 39312045
It was working so for all tense and purposes, your right...if it works don't worry about it.

Thanks!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question