troubleshooting Question

I need to make my existing Javascript Menu conditional within my ASP.Net/C# Application

Avatar of Eric Christianson
Eric ChristiansonFlag for United States of America asked on
* if statementsHTMLJavaScriptC#
32 Comments1 Solution201 ViewsLast Modified:
I have a large ASP.Net/C# application that uses a JavaScript menu.  The person who wrote the menu is long gone, and now I need users who log in to see different menu options on the pages.
I thought of two ways I can do this, and I cannot get either one to work because I do not understand JavaScript well enough.  I am using HTML 4.01.

First idea: add a few lines to the HTML HEAD section of pages to point to a different menu program based on a session variable I set in the Login page:
if (Session["UserType"].ToString() == 'external')
        <script language="JavaScript" src="MenuExternal.js" type="text/javascript"></script>
else
        <script language="JavaScript" src="MenuInternal.js" type="text/javascript"></script>

Second idea: add conditional if statements in the JavaScript program itself:
if (Session["UserType"].ToString() == 'external')
      startMenu('mUserMaintenance', true, 0, 18, 111, subM);
            addItem('&nbsp; External Users', 'MenuNav.aspx?From=Menu&To=EditUsers_External.aspx', '');
            addItem('&nbsp; My User Account', 'MenuNav.aspx?From=Menu&To=EditUsers_Me_Only.aspx', '');
else
      startMenu('mUserMaintenance', true, 0, 18, 111, subM);
            addItem('&nbsp; Internal Users', 'MenuNav.aspx?From=Menu&To=EditUsers.aspx', '');
            addItem('&nbsp; External Users', 'MenuNav.aspx?From=Menu&To=EditUsers_External.aspx', '');
            addItem('&nbsp; My User Account', 'MenuNav.aspx?From=Menu&To=EditUsers_Me_Only.aspx', '');

What I do not know how to do is mix C# (session variables) and JavaScript, or even if it's possible at all.  I have attached the JavaScript menu code.  The actual menu code that I modify regularly is about 2/3rds of the way down.

Thanks,
Eric Christianson
menu.js
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 32 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 32 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros