我正在我公司的网站上工作。我的任务是在用户登录后在网站的每个页面顶部显示用户的名称和ID。但是,每个页面的顶部由包含文件Header.inc控制。我通过一些VB / Javascript获取考生的名字和ID。问题是aspx页面在运行VB / javascript之前插入Include文件(如果你不熟悉我正在谈论的内容,请参见此处,在页面底部:http://www.w3schools.com/asp/asp_incfiles.asp)。基本上,Include文件中的代码在脚本声明之前引用名称和ID的变量。我目前知道的唯一解决方案是摆脱Include文件并在每个页面中插入html,但我想避免这种情况。我有什么想法可以解决这个问题?我读到Include文件是旧学校,我应该使用Master文件,但我真的不知道该怎么做。我是aspx开发的新手,并且正在修改我没有创建的现有网站。请在答案中尽可能具体。
提前致谢, 丹
以下是我在网页上遇到的错误: (仅供参考,网页为index.aspx)
Server Error in '/' Application.
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: BC30451: Name 'strName' is not declared.
Source Error:
Line 11: </br>
Line 12: </br>
Line 13: <a><%=strName%> </a>
Line 14: </br>
Line 15: <a>Examinee ID# <%=strNBCEID%> </a>
以下是包含文件的代码: (包含文件是Header.inc)
<!-- Start Header -->
<div class="container-header">
<div class="pageheader">
<a href="/home.aspx" > (text removed) Home</a> |
<a href="(link removed)" >(text removed)</a> |
<a href="/logout.aspx" >Logout</a> |
<a href="/contact.aspx" >Contact Us</a>
</br>
</br>
</br>
</br>
<a><%=strName%> </a>
</br>
<a>Examinee ID# <%=strNBCEID%> </a>
</div>
<div class="header">
<br />
<span id="menuiconspan">
<a onclick="showMenu()">
<img src="/images/menubutton.png" />
</a>
</span>
<span id="headermenulogospan-lg" >
<img src="/images/logow.png" height="73px" width="187.5" />
</span>
<span id="headermenulogospan-sm">
<img src="/images/logow.png" height="49px" width="125" />
</span>
</div>
</div>
<!-- End Header -->
以下是我的aspx文件的一些代码(我认为相关的部分): (网页名称为index.aspx,仅供参考)
<%@ Page Language="VB" Inherits="MySecurity" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Dim strName As String
Dim strAddress As String
Dim strPhone As String
Dim strEmailProc as String
dim strNBCEID as String
Protected Sub Page_Load()
Dim dvUser As Data.DataView
SecurityCheck()
sqlUser.SelectParameters("ExamineeNo").DefaultValue = Session("ExamineeNo")
dvUser = sqlUser.Select(DataSourceSelectArguments.Empty)
strName = dvUser.Table.Rows(0)("FirstName").ToString & " " & dvUser.Table.Rows(0)("LastName").ToString & " " & dvUser.Table.Rows(0)("Suffix").ToString
If dvUser.Table.Rows(0)("CurrentCountry").ToString = "1" Then
strAddress = dvUser.Table.Rows(0)("CurrentStreet").ToString & "<br />" & dvUser.Table.Rows(0)("CurrentCity").ToString & ", " & dvUser.Table.Rows(0)("CurrentState").ToString & " " & dvUser.Table.Rows(0)("CurrentZip").ToString
Else
strAddress = dvUser.Table.Rows(0)("CurrentStreet").ToString & "<br />" & dvUser.Table.Rows(0)("CurrentCity").ToString & " " & ZipFormat(dvUser.Table.Rows(0)("CurrentCountry").ToString, dvUser.Table.Rows(0)("CurrentZip").ToString) & "<br/>" & GetTableValueString("lkpCountry", "CountryName", "[CountryID]=" & dvUser.Table.Rows(0)("CurrentCountry").ToString)
End If
If dvUser.Table.Rows(0)("CurrentPhone").ToString <> "" Then
strPhone = Left(dvUser.Table.Rows(0)("CurrentPhone").ToString, 3) & "-" & Mid(dvUser.Table.Rows(0)("CurrentPhone").ToString, 4, 3) & "-" & Right(dvUser.Table.Rows(0)("CurrentPhone").ToString, 4)
Else
strPhone = ""
End If
strEmailProc = dvUser.Table.Rows(0)("Email").ToString
strNBCEID = dvUser.Table.Rows(0)("NBCEID").ToString
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>(text removed)</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script type="text/javascript" src="../js/template.js"></script>
<link href="../css/template.css" rel="stylesheet" />
<script language="javascript" type="text/javascript">
function PageLoad() {
}
</script>
<script type="text/javascript" src="../js/jquery-1.js"></script>
<script type="text/javascript" src="../js/jquery.js"></script>
</head>
<body onload="PageLoad()" onresize="resetMenu();">
<form id="form1" runat="server" requiressl="true">
<div>
<!-- #include virtual="~/include/sidenav.inc" -->
<!-- #include virtual="~/include/header.inc" -->
<div class="container">
<!-- #include virtual="~/include/leftcolumn.inc" -->
再次感谢