Link to home
Start Free TrialLog in
Avatar of Marc Davis
Marc DavisFlag for United States of America

asked on

Session variables included in quotes

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
Avatar of Paul MacDonald
Paul MacDonald
Flag of United States of America image

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?
Try this one:

"<%= Session['Test'] %>"
Avatar of Marc Davis

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of Paul MacDonald
Paul MacDonald
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
It was working so for all tense and purposes, your right...if it works don't worry about it.

Thanks!