javascript and session variable

hello all,
 I have a website made ¿¿with visual studio 2010. I use a javascript function to activate a menu option,  I want to activating the javascript in function of  a session variable.



in the default.aspx.vb load event
   Dim strQueryOutlet As String = Request.QueryString.Get("O") 'Si el valor es 1 es Outlet, si es O es promocion.
        If strQueryOutlet Is Nothing Then
            blnEsOutlet = True
        ElseIf strQueryOutlet = "1" Then
          blnEsOutlet = True
        ElseIf strQueryOutlet = "0" Then
            blnEsOutlet = False
        Else
            blnEsOutlet = True
        End If

        If blnEsOutlet Then
            Session("EsOutlet") = "1"
            Session("MenuOption") = "one"
        Else
            Session("EsOutlet") = "0"
            Session("MenuOption") = "two"
        End If

In the default.aspx
    <script type="text/javascript">
    if (<%=Session("MenuOption")%> = "one") {
        document.getElementById('uno').className = "activo";
        }
     if (<%=Session("MenuOption")%> = "two") {
         document.getElementById('dos').className = "activo";
        }
</script>

when I run the proyect...the default.aspx dynamic show... and the two if are executed...

and the two menu option are selected, and this is a mistake...

    <script type="text/javascript">
    if (one = "one") {
        document.getElementById('uno').className = "activo";
        }
     if (one = "two") {
         document.getElementById('dos').className = "activo";
        }
<




limmontreefreeAsked:
Who is Participating?
 
EyalConnect With a Mentor Commented:
   <script type="text/javascript">
    if ("<%=Session("MenuOption")%>" = "one") {
        document.getElementById('uno').className = "activo";
        }
     if ("<%=Session("MenuOption")%>" = "two") {
         document.getElementById('dos').className = "activo";
        }
0
 
EyalCommented:
or better...

    <script type="text/javascript">
    <%if (Session("MenuOption") = "one") then
        response.write "document.getElementById('uno').className = 'activo';"
        end if
     if(Session("MenuOption") = "two") then
         response.write document.getElementById('dos').className = 'activo';"
end if
       %>
0
 
limmontreefreeAuthor Commented:
thanks Eyal:

the first option don't wok when i run it raise the error:
run time error executing Jcript, it can't be assign a '[string]'

and this sentence has light the bulb, (i dont want assing nothing i only want to compare) and then i thy this... and now  it works fine
    <script type="text/javascript">
    if ("<%=Session("MenuOption")%>" == "one") {
        document.getElementById('uno').className = "activo";
        }
     if ("<%=Session("MenuOption")%>" == "two") {
         document.getElementById('dos').className = "activo";
        }
</script>

your second option don´t work in my code, i don't know why...
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.