[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

javascript and session variable

Posted on 2011-10-16
3
Medium Priority
?
476 Views
Last Modified: 2012-05-12
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";
        }
<




0
Comment
Question by:limmontreefree
  • 2
3 Comments
 
LVL 15

Accepted Solution

by:
Eyal earned 2000 total points
ID: 36975245
   <script type="text/javascript">
    if ("<%=Session("MenuOption")%>" = "one") {
        document.getElementById('uno').className = "activo";
        }
     if ("<%=Session("MenuOption")%>" = "two") {
         document.getElementById('dos').className = "activo";
        }
0
 
LVL 15

Expert Comment

by:Eyal
ID: 36975248
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
 

Author Comment

by:limmontreefree
ID: 36976151
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

Featured Post

Independent Software Vendors: 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!

Question has a verified solution.

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

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
This article discusses how to implement server side field validation and display customized error messages to the client.
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)
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…
Suggested Courses
Course of the Month17 days, 22 hours left to enroll

830 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