两个页面
第一个页面ButtonSearchTyped.aspx
<%@ Page Language="C#" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server">
public string SearchString
{
get
{
return txtSearch.Text;
}
}
</script><html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Button Search Typed</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="lblSearch" runat="server" Text="Search:"></asp:Label>
<asp:TextBox ID="txtSearch" runat="server"></asp:TextBox>
<asp:Button ID="btnSearch" runat="server" Text="Go!" PostBackUrl="~/ButtonSearchResultsTyped.aspx" />
</div>
</form>
</body>
</html>
第二个页面ButtonSearchResultsTyped
<%@ Page Language="C#" %>
<%@ PreviousPageType VirtualPath="~/ButtonSearchTyped.aspx" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server"> protected void Page_Load(object sender, EventArgs e)
{
if (PreviousPage != null)
{
lblSearch.Text = string.Format("Search For: {0}", PreviousPage.SearchString);
}
}
</script><html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Button Search Results Typed</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="lblSearch" runat="server" Text="Label"></asp:Label>
</div>
</form>
</body>
</html>
问题是:第二个页面里的
protected void Page_Load(object sender, EventArgs e)
{
if (PreviousPage != null)
{
lblSearch.Text = string.Format("Search For: {0}", PreviousPage.SearchString);
}
它为什么说我的PreviousPage.SearchString没有被定义?????
第一个页面ButtonSearchTyped.aspx
<%@ Page Language="C#" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server">
public string SearchString
{
get
{
return txtSearch.Text;
}
}
</script><html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Button Search Typed</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="lblSearch" runat="server" Text="Search:"></asp:Label>
<asp:TextBox ID="txtSearch" runat="server"></asp:TextBox>
<asp:Button ID="btnSearch" runat="server" Text="Go!" PostBackUrl="~/ButtonSearchResultsTyped.aspx" />
</div>
</form>
</body>
</html>
第二个页面ButtonSearchResultsTyped
<%@ Page Language="C#" %>
<%@ PreviousPageType VirtualPath="~/ButtonSearchTyped.aspx" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server"> protected void Page_Load(object sender, EventArgs e)
{
if (PreviousPage != null)
{
lblSearch.Text = string.Format("Search For: {0}", PreviousPage.SearchString);
}
}
</script><html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Button Search Results Typed</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="lblSearch" runat="server" Text="Label"></asp:Label>
</div>
</form>
</body>
</html>
问题是:第二个页面里的
protected void Page_Load(object sender, EventArgs e)
{
if (PreviousPage != null)
{
lblSearch.Text = string.Format("Search For: {0}", PreviousPage.SearchString);
}
它为什么说我的PreviousPage.SearchString没有被定义?????
如果没有这个指令 PreviousPage属性会把前页面作为通用的Page类的实例返回