Milonic provide full featured pull down web menus for some of the worlds largest companies
click here to see what it can do for you

Download Milonic DHTML Menu
Buy Milonic DHTML Menu

Back To Start Of Archive
Taken From The Forum: Help & Support for DHTML Menu Version 5+
Forum Topic: Click to view post
Last Updated: Saturday July 14 2012 - 06:07:16

Using ASP Session Variables to Adjust Menu


Poster: waynem
Dated: Tuesday September 2 2008 - 18:42:57 BST

I'd like to be able to determine what options appear based on session variables.

For example, if someone enters through site page A, they would see a menu relevant to site page A. Most of the menus would be the same, but a few would need to change.

Is this possible using ASP session variables, and if so how could I do this?

Is there a better way to manipulate the menus?

I'd rather have 1 data file than 100 to update.

Thanks!

Re: Using ASP Session Variables to Adjust Menu


Poster: John
Dated: Tuesday September 2 2008 - 23:12:28 BST

The menu_data.js file can actually have any suffix - .cfm, .js, .php, .asp, etc. So, change yours to menu_data.asp and code whatever you need for the menu using .asp statements where necessary.

/extras/ in the menu download has an ASP example.

HTH...

Re: Using ASP Session Variables to Adjust Menu


Poster: waynem
Dated: Tuesday September 2 2008 - 23:31:18 BST

Thanks, John, that fits better into my knowledge base!

But if I rename the page, what about all the code from the .js page? Do I have to wrap that in <script type="text/javascript"></script> ever time I insert asp code?

Re: Using ASP Session Variables to Adjust Menu


Poster: waynem
Dated: Tuesday September 2 2008 - 23:41:48 BST

sorry, I can't find an asp sample from the extras folders, only an asp with sql

Re: Using ASP Session Variables to Adjust Menu


Poster: Ruth
Dated: Wednesday September 3 2008 - 18:05:44 BST

There is a folder called asp_sqlserver, that has the asp example.

Ruth

Re: Using ASP Session Variables to Adjust Menu


Poster: waynem
Dated: Wednesday September 3 2008 - 19:54:47 BST

sorry, I don't see anything that would help me. The one asp file contains this:

<script language=JavaScript src="milonic_src.js" type=text/javascript></script>
<script language=JavaScript>
if(parent.frames.length){top.location=document.location}
if(ns4)_d.write("<scr"+"ipt language=JavaScript src=mmenuns4.js><\/scr"+"ipt>");
else _d.write("<scr"+"ipt language=JavaScript src=mmenudom.js><\/scr"+"ipt>");
</script>

which is how I call my data file, not the data file itself.

The rest of the document contains ASP code to implement a menu using a SQL database, which is not what I am doing.

I need to see a data file sample in ASP that contains the same code as the data.js file, which is not here.

Does anyone else out there use ASP for their data file, and if so would you be willing to share that file with me so I can see how it is put together?

Re: Using ASP Session Variables to Adjust Menu


Poster: Ruth
Dated: Thursday September 4 2008 - 3:16:30 BST

Hi,

I think you misunderstand. The data file is what it is, it doesn't matter if it is for an asp, php, cfm or js file. If you want to use asp coding in the data file, then you would save the file as menu_data.asp. This means that the file will be processed through the asp processor or whatever it is that 'processes' asp coding, just like a data file named menu_data.php will go through the php processor.

So, what you need to do is know how to put in the asp codes/statements whatever you call them into the file. I don't know asp, so I can't help you on that. I can give you an example, which is one from John, which uses cold fusion statements inside the data file.

1. He has renamed the data file to .cfm extension, that is the only file that gets renamed.

2. This is a menu inside that file which uses cold fusion statements:

Code:
with(milonic=new menuname("system")){   
style=XPMenuStyle;
borderwidth=1;
orientation="vertical";
aI("text=Browser: <cfoutput>#cgi.http_user_agent#</cfoutput>;image=/sai/graphics/xpblank.gif;");
aI("text=Code Name: "+navigator.appCodeName+";image=/sai/graphics/xpblank.gif;");
aI("text=Color Depth: "+screen.colorDepth+" bit;image=/sai/graphics/xpblank.gif;");
aI("text=IP: <cfoutput>#cgi.remote_addr#</cfoutput>;image=/sai/graphics/xpblank.gif;");
aI("text=Language: "+navigator.browserLanguage+";image=/sai/graphics/xpblank.gif;");
aI("text=Platform: "+navigator.platform+";image=/sai/graphics/xpblank.gif;");
aI("text=Screen Max: "+screen.availWidth+"  x  "+screen.availHeight+";image=/sai/graphics/xpblank.gif;");
aI("text=Screen Resolution: "+screen.width+"  x  "+screen.height+";image=/sai/graphics/xpblank.gif;");
}


So, the result is that since the data file is renamed to a .cfm extension it gets processed by the cold fusion processor which reads that cold fusion statement and does whatever the statement is telling it to do. As to the rest of the data file info, it is just rendered as it is. If there is no cold fusion statement/call/function then whatever is in the file is just rendered as the menu. Not sure I am explaining this very clearly, but I hope you can get the idea :)

Ruth

Re: Using ASP Session Variables to Adjust Menu


Poster: waynem
Dated: Thursday September 4 2008 - 21:31:22 BST

The problem is it doesn't work.

If I rename the page and add ASP code, the menus stop loading.

I've tried adding one simple line of ASP code which I replicated in another asp file. The asp file ran fine and displayed the output I was coding, but the milonic data file, renamed data.asp, would not load menus after that same snippet of code was included within asp tags. If you don't include asp tags, it thinks you are using java and asks for the ;

So it is really tough to figure this out since it is not working, but I appreciate the feedback.

Re: Using ASP Session Variables to Adjust Menu


Poster: John
Dated: Thursday September 4 2008 - 21:48:01 BST

Not being an ASP coder, I have to ask - does that code include ';'? If so, you'll need to escape it wherever it's used. Remember, the items in a 'normal' aI statement are separated with a ; , so seeing the ; without an escape will confuse the menu code..

HTH...

Re: Using ASP Session Variables to Adjust Menu


Poster: waynem
Dated: Thursday September 4 2008 - 22:54:48 BST

I think I've figured it out. I'm not really a programmer but I try to get by.

You call the block using this line:
<script src="menu_data.asp" type="text/javascript"></script>

but this tells the server that whatever is inside that file is javascript, no matter what you name the file. That is why you can name it anything and it still works - you've already informed the program its javascript, it doesn't care about the extension. But if you try to use that page for asp it fumbles because it thinks its a javascript page, and despite the extension it really is.

So I changed that line to this:
<!--#include file="menu_data.asp"-->

which tells asp that you are including an asp file into the calling file. This allows you to use asp code in the block being callled.

Ok, but now the data file still contains java text, so we have to add this to make that work:
<script type="text/javascript"> before the first line, and </script> after the last. Now it knows this asp block contains javascript just like a "normal" asp page. ASP is ok with that, and its ok with adding asp code inside using the asp tags of <% and %>

One caveat I ran into is using a response.write does not work inside the javascript block, so I have to end the block, insert the response.write statement, then re-open a new javascript block to work around this. I don't really need that personally, what I need are if then statements to hide and show menus based on a session variable, and so far that seems to work.

I will do further testing but so far so good. If this works it will prevent me from having to maintain 100 different data pages. By using session variables to decide what menus appear or what the URL name is, this becomes really convenient and powerful. If I change a menu or add a new menu, I can do it in this one data file and all my subdomains will be updated at the same time.

Example, I have 50 sites with "about" pages that are all different and located in directories off of the root. A visitor initiates a session variable called "site" when they bring up that site's home page. By standardizing on names and directories, I can then code the milonic data file to call for "site1"/about.asp instead of directory1/about.asp - and if a person then visits another site, their menu will look exactly the same but the URL will now point to "site2"/about.asp instead of "site1"/about.asp. If they navigate back to site1, the about URL again reverts back to "site1"/about.asp. It's dynamic.

Since everything is maintained in 1 data file, if I decide that I want to add a "contact me" page I can add it with the same session variable, and every site under the domain will reflect the same updated structure. Of course I'd have to add "contact me" pages to each directory but that is a one time thing. Editing 50 milonic data files every time a change is needed would be a real pain.

Lets say I wanted to change the font on the menu - one file to change. Makes life much much easier.

Hopefully this will work!

Re: Using ASP Session Variables to Adjust Menu


Poster: Andy
Dated: Friday September 5 2008 - 11:09:19 BST

response.write will work inside the file but you MUST ensure that what you are sending is valid javascript.

In response to your tech support ticket (thought I'd bring the discussion on here, hope you don't mind) I see that you said you tried
Code:
<% response.write "<p /><br /><br />Site: " %>
Unfortunately, that is HTML and will inevitably break the script.

whatever you put between <% and %> can be any ASP code and as long as it does not echo anything as plain text the script will be fine.

as I said in response to your support ticket, this will work fine:

Hi,

As long as you change the file extension for the menu_data.js file to menu_data.asp, you can then parse ASP through the data file

This should be possible like so:

Code:
<%
if session=blue then
%>
with(milonic=new menuname("submenu1")){
style=menuStyle;
aI("text=Session Blue;url=http://www.milonic.com/;");
}
<%
else
%>
with(milonic=new menuname("submenu1")){
style=menuStyle;
aI("text=Session Not Blue;url=http://www.milonic.com/;");
}
<%
end if
%>


Note that the if-else-end if statements are encased inside <% and %> tags but the actual JavaScript is native to the file.

Have you tried viewing the actual contents of the page. For example, if you had a .asp file located at menu.asp on your server, have you tried accessing http://yourdomainname.com/menu.asp and seeing what the output is like, this will help you to see exactly how the file has been parsed.

HTH,
Andy

Re: Using ASP Session Variables to Adjust Menu


Poster: waynem
Dated: Friday September 5 2008 - 13:34:02 BST

Thanks for the response - that makes sense regarding response.write and html.

I can't directly view the data page because it doesn't know what mm_style is as that has not been called.

I am going to try to put this into practice today, I'll post again if I run into any problems but I'm optimistic that the way I've implemented this will now work the way I need it to.