Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

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
JavaScriptHTMLC#* if statements
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