Question about asp and include files

Hello,

I have a question, that I've been wondering about for quite a while, that I never got around to answering.

I've got a website. The entire site has a standard top logo section and a standard menu section. It makes perfect sense to use include files here to keep the design consistent and to minimize headaches when updating the site. However, one problem with this approach is that when someone is on my homepage, and point points their mouse at the logo, a little text popup says "Click here to return to the homepage." (The text that's in the image alt property). The same thing follows for the menu. When someone is on the services page, and points their mouse at the services link, they get a little popup that says "Click here to learn about our web design services." That would indicate to the typical "non-programmer" that clicking on that link will bring them to another page which obviously is not the case. Also, I'd like to have a different image in the place of the currently active link on the menu bar that would indicate to the user what page they're currently on.

First of all, can you write server side code in include files and if so, how would I go about checking to find out if the current page is xyz.asp? For example, if my menu has 3 links, page1, page2 and page3. I would need something that would go something like this:
If currentPage = page1 then
display page1 active image
else if currentPage = page2 then
display page2 active image
else if .....

You get the point. Can this be done from within an include file and if so how? Any input would be greatly appreciated.

Thanks,
Ryan
 
Sure you can. I use similar technique on one of my sites. First of all make the included page an ASP file (with .asp extention). Now you can run scripts in it. I use Request.ServerVariables("SCRIPT_NAME") to find out the page. Note, that you get the full path to your page with this function, relative to root. E.g. your script is "www.mydomain.com/hello/there/oups.asp", you will get "/hello/there/oups.asp". So you may need to parse it to find the name of file exact.
 
Works like a charm. Thanks for the input. Although, I suppose I should let you know something... after thinking about your reply, I came to the conclusion that you were wrong about something. The include file, where I put the request.servervariables("script_name"), does not need to be renamed to have a .asp extension. If that code needed to in an executable include file (a file with an asp extension), then that code would then be running in that executable include file, and therefore the string returned by the script_name variable would be something like included_file.asp instead of "file_that_calls_the_include.asp".

Did I explain that right?

Either way, your solution worked. Now I've just got to go through my include file and recode some of it.

Thanks again,
Ryan
 
Probably you are right, I haven't tried, as I'm always use .asp extension, but from a different reason - do not want anyone to look into my scripts, even if they are just included files :)
 
StPatrick said:
Probably you are right, I haven't tried, as I'm always use .asp extension, but from a different reason - do not want anyone to look into my scripts, even if they are just included files :)
I also use ".asp" extension with my include files so they are run from the server instead of downloaded if a user accesses them directly. And Ryan is correct about not needing .asp on the end to run the code inside. All include files are included into the calling document first, before anything on the page is executed.
 
have you thought about using asp.net to do your coding? you can do a lot of different stuff with codebehinds. We have a site here that has the same sort of issue. I have the same header and footer and the links on the right side will always be the same but I want to highlight the selected one.

One of the things you can do is create a class that inherits from Page and insert different controls. You can have a header control and a footer control as well as a menu control. Then all you would have to do is every page after that you would inherit from your new Page(template). Look into creating templates in asp.net. It is was a lot of people are using today for all those little issues of having the same header and footer.
 
Actually, I just got an ASP.Net book. I'm going to read through it in the next couple of weeks and start learning it, but as of yet, I haven't had time to sit down and focus on learning .Net. When if first came out, I got the impression it was Micrsoft's way of making more money of the same old "stuff", but more and more I'm starting to hear that it really is worth learning. We'll see about that. :)

Ryan
 
What I can tell you if you are doing ASP then ASP.NET is a real difference. I thought the same thing that you thought about microsoft just wanted to make more money, but what I can tell you is that the future is with .NET if you are talking about Microsoft. I am using ASP.NET with C#....I used to be a java programmer and I didn't like how asp worked but with working with ASP.NET it is a 180 degree turn around for Microsoft. There is so much more power there. Your include problem would be solved very quick and you can change it as many times as you want and your user would have no clue.

Just a thought...If you are looking for a future in the work force with Microsoft products then I would suggest learning and developing in ASP.NET and either VB.NET or C#.NET
 
Back
Top