Solved

Session variables included in quotes

Posted on 2013-05-16
6
230 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 33

Expert Comment

by:paulmacd
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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 33

Accepted Solution

by:
paulmacd 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now