views:

80

answers:

3

Hi All,

I am creating Accordion menu using JQuery. I want to hide links according to the user status. How to pass values from code behind to jquery during pageload?

Eg:

UserA: Menu header: headerA and HeaderB

UserB: Menu header: headerB and HeaderC

I want to pass header names to jquery to hide it.

Geetha

A: 

I assume that by 'user status' you mean logged in/logged out. So, If you are using a server side templating languages, such as JSP/JSTL, you can easily do a <c:choose /> and add the links in your HTML page. Like,

<c:choose>
    <c:when test='${user.loggedin == "yes"}'>

    Hello, <c:out value='${user.name}' />   <a href="#">Log out</a>
    </c:when>
    <c:otherwise>
        <a href="#">Log in</a>
    </c:otherwise>

</c:choose>
Veera
Thank you for your reply. i have edited the post please check it.
Geetha
A: 

It's best to print style="display:none;" in tags you want to hide on the server-side because otherwise they will be visible to the user while the page is loading and then disappear when the javascript is executed (especially in slow browsers). This way the link will be hidden while the page is loading as well.

E.g:
<a href="#" style="display:none;">Hidden Link</a>

Rowno
A: 

Hi,

I got solution by using the following code.

$.ajax({
        type: "POST",
        url: "NavigationMenu.aspx/UserStatus",
        contentType: "application/json; charset=utf-8",
        data: "{}",
        dataType: "json",
        success: AjaxSucceeded,
        error: AjaxFailed
    });   
Geetha