?
Solved

Session variables included in quotes

Posted on 2013-05-16
6
Medium Priority
?
238 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 750 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
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…
Suggested Courses

752 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