Jquery Menu State

0

Here's what I'm trying to do... It's quite simple and obviously there must be something wrong in what I'm doing but I can't see it, hope you can help me... I have a Vertical Jquery Menu (using accordions) that I want to remember its state. So, I have this code in my Master Page to handle each click over the accordions:

$(document).ready(function () {
    var toOpen = <%= MySessionInfo.Current.MyMenu %>;
    if(toOpen != -1){            
        $("#accordionMenu").accordion( "activate", toOpen); 
    }

    $("#accordionMenu").click(function (){
        var activate = $("#accordionMenu").accordion("option", "active");
        if (activate != false) {
            $.getJSON("/Account/SetMenu", { CurrentMenu: activate }, function (j) {});
        }
    });
 });

Then I have the Partial View with the Menu defined as a set of divs in which there are one ul and lots of li links for each section.

And in my Account Controller I use this:

public void SetMenu(int CurrentMenu)
{
    MySessionInfo.Current.MyMenu = CurrentMenu;    

}

What's going on?: It works fine in the beginning and saves the state ok but when the next page loads it wont refresh the status. I also observed that right exactly after the "SetMenu" is called from the view and right before going to the called view this error happens:

uncaught exception: [Exception... "Component returned failure code: 0x80040111 (NS_ERROR_NOT_AVAILABLE) [nsIXMLHttpRequest.getAllResponseHeaders]" nsresult: "0x80040111 (NS_ERROR_NOT_AVAILABLE)" location: "JS frame :: http://localhost:20984/Scripts/jquery-1.4.2.min.js :: anonymous :: line 7207" data: no]

I hope you can give me hand on this issue soon... Regards!

ajax
jquery
asp.net-ajax
asked on Stack Overflow Feb 22, 2011 by met.lord

2 Answers

0
var toOpen = '<%= MySessionInfo.Current.MyMenu %>';
answered on Stack Overflow Feb 22, 2011 by Val
0

The solution is a lot stranger than the question itself. I created a javascript function "updateMenu()" that calls the jquery "activate" and I call it in the end of the body as window.onload=updateMenu:

function updateMenu(){
    var toOpen = <%= MySessionInfo.Current.MyMenu %>;
    if(toOpen != -1){            
        $("#accordionMenu").accordion( "activate", toOpen); 
    }
}

window.onload=updateMenu;

I'm not sure why it works this way and not the other, but it worked fine for me.

answered on Stack Overflow Feb 22, 2011 by met.lord

User contributions licensed under CC BY-SA 3.0