Solved

Session variables included in quotes

Posted on 2013-05-16
6
234 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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 …
When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

762 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