3

我按照教程:从 MSDN 上的源页面获取公共属性值,我创建了一个新的 Web 表单站点并创建了以下两个页面。他们工作得很好。现在,如果我将这些复制粘贴到我的其他 Web 窗体项目中,则 PreviousPage == null。我不知道问题可能是什么。没有任何错误。我只是得到

messageSTr.Text = "Not a cross-page post.";

更新:我删除了页面声明中的 MasterPage 引用,但我仍然收到错误。我将此项目 web.config 复制到另一个正在工作的项目中,它仍然有效。它不是我的网络配置,我在这里完全不知所措。这是我的应用程序所需的重要工具。

此页面提交到第 1 页

<%@ Page 
Title="" 
Language="C#" 
MasterPageFile="~/Site.Master" 
AutoEventWireup="true" 
CodeBehind="WebForm2.aspx.cs" 
Inherits="WebApplication5.WebForm2" %>


<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="server">
<asp:Button id="button1" Text="Submit to PostBackUrl" PostBackUrl="~/WebForm1.aspx" runat="server"/>

此页面接收提交

<%@ Page 
Title="" 
Language="C#" 
MasterPageFile="~/Site.Master" 
AutoEventWireup="true" 
CodeBehind="WebForm1.aspx.cs" 
Inherits="WebApplication5.WebForm1" %>
<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="server">
<asp:Label ID="messageSTr" runat="server"></asp:Label>

WebForm1.aspx.cs

protected void Page_Load(object sender, EventArgs e)
    {


        if (PreviousPage != null)
        {
            if (PreviousPage.IsCrossPagePostBack == true)
            {
                messageSTr.Text = PreviousPage.imaliveStr;
            }
        }
        else
        {
            messageSTr.Text = "Not a cross-page post.";
        }
    }
4

1 回答 1

1

问题是 FriendlyUrls nuget 包在我的页面名称后删除了 .aspx,所以我的目标页面不是 WebForm2.aspx,而只是 WebForm2。这使得前一页为空。

于 2014-01-24T21:00:36.620 回答