Solved

Passing variables between ASP Include files

Posted on 2008-06-11
9
2,541 Views
Last Modified: 2013-11-18
I am trying to make my site easier to maintain, and want to use include files. The idea here is have each segment of code in an include file, and select what page it is for navigation etc. with a simple index number. I have the sitemap in a spreadsheet that exports the case function in ASP, so updating the site will be a breeze.
So how do I get the passing of that variable between these different navX.asp pages to make this concept work?

As you can see, the main page becomes very easy to maintain- Navigation, nav-crumbs across the top, page titles, links etc. are all maintained in my spreadsheet and called with 1 number. This page works fine when it is all put together in one file.. -> http://vacorp.com/common/demo1.asp

I posted the question in the [H]ardforum- been a member there a long time, you can see the post there : http://www.hardforum.com/showthread.php?p=1032603666#post1032603666 -the formatting makes it easier to digest.
Main Page:
[CODE]
<!--#include virtual="/common/nav1.asp"-->
 
NavIndex = 7
 
<!--#include virtual="/common/nav2.asp"-->
<!--#include virtual="/common/body1.asp"-->
<!--#include virtual="/common/body2.asp"-->
        	
<div id="mainContent">
           <h1> Main Content </h1>
                <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</p>
                <p>Quisque ornare risus quis  ligula.< /p>
            <h2>H2 level heading </h2>
                <p>Lorem ipsum dolor amet, consectetuer adipiscing elit.</p>
</div>
            
<!--#include virtual="/common/body3.asp"-->
[/CODE]
 
nav1.asp:
[CODE]<%
DIM siteMapLocation, sideNavIndex, NavIndex, topLinks, currentDate
[/CODE]
 
nav2.asp (truncated the CASE options for brevity, there are about 30 options):
[CODE]currentDate = FormatDateTime(date(), 1)
currentTime = FormatDateTime(now(), 3)
 
 
SELECT CASE NavIndex
	CASE 1
	topLinks = "<a href=""/index.asp"">Home</a>"
	sideNavIndex="n01"
	CASE 2
	topLinks = "<a href=""/index.asp"">Home</a> > <a href=""/CS/index.asp"">Customer Service</a>"
	sideNavIndex="n09"
	CASE 3
	topLinks = "<a href=""/index.asp"">Home</a> > <a href=""/CS/index.asp"">Customer Service</a> > <a href=""/CS/Individuals/index.asp"">Individuals</a>"
	sideNavIndex="n09"
	CASE 4
	topLinks = "<a href=""/index.asp"">Home</a> > <a href=""/CS/index.asp"">Customer Service</a> > <a href=""/CS/Dealers/index.asp"">Dealers</a>"
	sideNavIndex="n09"
END Select %>
[/CODE]
 
body1.asp (HTML Header information):
 
[CODE]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
 
	<head>
		<title>Vehicle Acceptance Corporation - VACorp.com</title>
		<link rel="stylesheet" type="text/css" href="../screenstyles.css" media="screen"/>
        	<link rel="stylesheet" type="text/css" href="../printstyles.css" media="print"/>
        
		<script type="text/javascript" src="../jquery.js"></script>
		<script type="text/javascript" src="../sliding.js"></script>
        <script type="text/javascript" src="../bookmark.js"></script>
        <script type="text/javascript" src="../date.js"></script>
        
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />        
[/CODE]
 
body2.asp (side navigation, images, some CSS styling for the side navigation):
 
[CODE]
		<style type="text/css" media="screen">	
			div#bottomLocation {position:relative; left: 0em; top:8em; height:4em; Z-INDEX: 10;}
			ul#sideNavList li.navLink div.<%response.Write(sideNavIndex)%> a {color:#FF0000;}
	        	ul#sideNavList li.navLink div.<%response.Write(sideNavIndex)%> a:hover {color:#FF0000;} 
			ul#sideNavList li.navLink div.<%response.Write(sideNavIndex)%> a span.{color:#FF0000;}
			ul#sideNavList li.navLink div.<%response.Write(sideNavIndex)%> a span.current{color:#FF0000;}
	        	ul#sideNavList li.navLink div.<%response.Write(sideNavIndex)%> a:hover span.current {color:#FF0000;}
		</style>
        
        <style type="text/css" media="print">
			div#bottomLocation {position:relative; left: 0em; top:8em; height:4em; Z-INDEX: 10;}
			ul#sideNavList li.navLink div.<%response.Write(sideNavIndex)%> a {color:#FF0000; background-color:#FFCC33; font-weight:bold;}
	        	ul#sideNavList li.navLink div.<%response.Write(sideNavIndex)%> a:hover {color:#FF0000; font-weight:bold;} 
			ul#sideNavList li.navLink div.<%response.Write(sideNavIndex)%> a span.{color:#FF0000;}
			ul#sideNavList li.navLink div.<%response.Write(sideNavIndex)%> a span.current{color:#FF0000;}
	        	ul#sideNavList li.navLink div.<%response.Write(sideNavIndex)%> a:hover span.current {color:#FF0000;}
		</style>
        
        
	</head>
	<body class="bodyStyle">
    <div id="headerContainer"> 
        	<div class="Logo"><img src="/images/Common/VACLogo_Web.gif" alt="" width="188" height="150" /></div>
            <div class="LogoTail"><img src="/images/Common/VACLogo_WebTail.gif" alt="" width="100%" height="150"/></div>
            <div class="GradientTop"><img src="/images/Common/Gradient_top.jpg" alt="" width="100%" height="180"/></div>
            <div class="VAC"><img src="/images/Common/VAC.gif" alt="Vehicle Acceptance Corporation"/></div>
        	<div class="VACPrint"><img src="/images/Common/VACTopPrint.jpg" alt="Vehicle Acceptance Corporation" width="750"/></div>
            <div class="VACMotto"><img src="/images/Common/CashandServiceSolutions.gif" alt="" width="300" height="47" /></div>
        </div>
        
    	<div class="GreyNavBar"><div class="topNav"><span class="topNavTimestamp"><%response.Write(currentDate)%> - <%response.Write(currentTime)%> - </span><a onClick="window.print()" href="#">Print</a> - <a href="../EMailPage.asp" target="_blank">E-Mail this page</a> - Navigation: 
      <%response.Write(topLinks)%></div>
    </div>
        
<div id="bodyContainer">
            
            <div id="sideNavBlock">
              <ul id="sideNavList">
                    <li class="navLink"><div class="n00"><a>HOME</a></div></li> 
                    <li class="navTitle">For Customers</li>
                    <li class="navLink"><div class="n01"><a href="/contact/index.htm">Update Your Information<span>Provide VAC updates to your current contact or vehicle information.</span></a></div></li>
                    <li class="navLink"><div class="n02"><a href="/payment/index.htm">Make Your Payment<span><img src="file:///E|/Users/jneubauer/Documents/Websites/Vehicleacceptance.com/Current_VAC_Website/Website_05012008/images/common/CC_Small.gif" alt="Visa, Mastercard, AMerican Express, Discover Credit and Debit Cards Accepted" width="70%" height="70%"/>Arrange payments via online ACH, Online Credit or Debit Cards, Pay-By-Phone or Western Union</span></a></div></li>
                    <li class="navLink"><div class="n03"><a href="/payment/index.htm">Request Your Payoff<span>Request the current amount due to payoff your note</span></a></div></li>
                    <li class="navTitle">For Businesses</li>
                    <li class="navLink"><div class="n04"><a href="/repair/index.htm">Repair Industry Services<span>Find out how VAC can help your repair business convert economically challenged traffic into sales</span></a></div></li>
                    <li class="navLink"><div class="n05"><a href="/advance/index.htm">BHPH Cash Advance<span>Independent businesses receive an advance of 3 to 9 months of payments on your notes, while retaining ownership</span></a></div></li>
                    <li class="navLink"><div class="n06"><a href="/servicing/index.htm">BHPH Note Servicing<span>Independent dealers retain ownership of your receivables while allowing us to collect payments and service your contract for you.</span></a></div></li>
                    <li class="navLink"><div class="n07"><a href="/purchasing/index.htm">BHPH Bulk Purchasing<span>Learn more about our bulk note purchasing program</span></a></div></li>
                    <li class="navTitle">For Everyone</li>
                    <li class="navLink"><div class="n08"><a href="/contact/index.htm">Customer Service</a></div></li>
                    <li class="navLink"><div class="n09"><a href="/locations/index.htm">Locations</a></div></li>
                    <li class="navLink"><div class="n10"><a href="/locations/index.htm">VAC News</a></div></li>
                    <li class="navLink"><div class="n11"><a href="/online/index.htm">Online Solutions</a></div></li>
                    <li class="navLink"><div class="n12"><a href="/about/index.htm">About Us</a></div></li>
                    <li class="navTitle">Interactive</li>
                    <li class="navLink"><div class="n13"><a href="/locations.htm">Login</a></div></li>
                </ul>
            </div>
        [/CODE]
 
body3.asp (bottom feedback form, links etc. end of HTML) :
 
[CODE]
            <!-- Bottom set of navigation options, disclaimer, etc.. -->
                        
...
 
            <!-- END OF Bottom Navigation Set -->
            </div>	
		</div>       
</body>
</html>[/CODE]

Open in new window

0
Comment
Question by:jen4950
  • 4
  • 4
9 Comments
 
LVL 15

Accepted Solution

by:
dosth earned 250 total points
ID: 21766874
declare all variables in global.asa file
0
 
LVL 14

Expert Comment

by:_Stilgar_
ID: 21766900
Or use Session variables, or just declare a variable in the head of your page, and reference it in the include files (for this you will have to make sure it is declared before each file including those files).

Stilgar.
0
 

Author Comment

by:jen4950
ID: 21769955
So can I declare a session variable in the nav1.asp, and have it utilized in nav2.asp, body1,asp etc?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 15

Expert Comment

by:dosth
ID: 21770089
yes, the session variable needs to be in the top leve page so you can call it any page
0
 

Author Comment

by:jen4950
ID: 21770834
Sorry for being a noob here, but is this what the global.asa file would look like? And what happens when a user has cookies disabled? Is an application variable a better solution? And finally, how do I call the variable in my include files, where typically is would be: "SELECT CASE NavIndex" or "<%response.Write(sideNavIndex)%>"
<SCRIPT LANGUAGE="VBScript" RUNAT="Server"> 
 
Sub Application_OnStart 
 
application("activevisitors")=0 
 
End Sub 
 
Sub Application_OnEnd 
End Sub 
 
Sub Session_OnStart 
application.lock 
application("activevisitors")=application("activevisitors")+1 
application.unlock
 
session("siteMapLocation")=""
session("sideNavIndex")=""
session("NavIndex")=""
session("topLinks")=""
session("currentDate")=""
session("currentTime")=""
 
End Sub 
 
Sub Session_OnEnd 
application.lock 
application("activevisitors")=application("activevisitors")-1 
application.unlock 
End Sub 
 
</SCRIPT>

Open in new window

0
 
LVL 15

Assisted Solution

by:dosth
dosth earned 250 total points
ID: 21770961
yes global.asa look like this only.

session will work

<%response.Write(session("NavIndex"))%>
0
 

Author Comment

by:jen4950
ID: 21771012
Last question- do I have to worry about functionality if the user has cookies disabled?

Thanks so much for your help!
0
 
LVL 15

Assisted Solution

by:dosth
dosth earned 250 total points
ID: 21771097
no, session is server side
0
 

Author Comment

by:jen4950
ID: 21771104
Excellent, Thank you so much!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
There’s a good reason for why it’s called a homepage – it closely resembles that of a physical house and the only real difference is that it’s online. Your website’s homepage is where people come to visit you. It’s the family room of your website wh…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question