Solved

Passing variables between ASP Include files

Posted on 2008-06-11
9
2,522 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
 
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…

747 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now