PreviousPage is null when attempting a cross-page postback using a button and the PostBackURL attribute

StackOverflow https://stackoverflow.com/questions/21244928

Domanda

I followed the tutorial: Getting Public Property Values from the Source Page on MSDN and I started a fresh Web Forms site and created the below two pages. They work just fine. Now, if I copy paste these into my other Web Forms project then PreviousPage == null. I have no idea what the issue could be. There is no errors whatsoever. I just get

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

UPDATE: I deleted the MasterPage reference in the page declaration and im still getting the error. I copied this projects web.config to the other working one and it still works. Its not my web config, I am at a complete loss here. This is a vital tool that I need for my application.

This page submits to page 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"/>

This page receives the submit

<%@ 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.";
        }
    }
È stato utile?

Soluzione

The problem was the FriendlyUrls nuget package was removing the .aspx after my page names so my target page was not WebForm2.aspx but just WebForm2. This made the previous page null.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top