この MSDN の記事に従って、クロスページ投稿を試しています。私はこのコードを持っています:
CrossPagePosting1.aspx
<form id="form1" runat="server">
<h1>Page 1</h1>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br />
<asp:Button ID="Button1" runat="server" Text="Button" PostBackUrl="CrossPagePosting2.aspx"/>
</form>
CrossPagePosting2.aspx
<form id="form1" runat="server">
<h1>Page 2</h1>
<asp:Label ID="Label1" runat="server" Text=""></asp:Label>
</form>
CrossPagePosting2.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
TextBox TextBox1 = (TextBox)Page.PreviousPage.FindControl("TextBox1");
Label1.Text = TextBox1.Text;
}
上記のコードはNullReferenceException
at を生成しPage.PreviousPage
ます。なんで?
これは ASP.Net 4.0 アプリケーションです。
デフォルトの FriendlyUrls を使用します。
注:PreviousPageType
ディレクティブなどを使用して、前のページを強く型付けしたくありません。参照記事によると、これは必要ないはずです。