我按照教程进行操作:在MSDN上Getting Public Property Values from the Source Page,我开始了一个新的Web窗体站点,并创建了以下两个页面。他们工作得很好。现在,如果我将这些内容复制粘贴到其他Web窗体项目中,则PreviousPage == null。我不知道可能是什么问题。没有任何错误。我刚得到

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


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

本页面提交至第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.";
        }
    }

最佳答案

问题在于,FriendlyUrls nuget软件包在页面名称后删除了.aspx,因此我的目标页面不是WebForm2.aspx,而是WebForm2。这使上一页为空。

关于c# - 当尝试使用按钮和PostBackURL属性进行跨页回发时,PreviousPage为null,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21244928/

10-10 02:57