Documentation - PreviousPage

J

Jim McGivney

I have been trying to get the values from a previous page on my target page.
I have followed the help article:
ms-help://MS.VSExpressCC.v80/MS.NETFramework.v20.en/dv_aspnetcon/html/fedf234e-b7c4-4644-a9e8-c1c0870b043b.htm

I do not see any deviations from the paosted code, yet the application
throws an : "Object reference not set to an instance of an object." error

Any suggestions would be appreciated. My complete code for both pages is
listed below .

Thanks in advance for your help,
Jim

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="SourcePage.aspx.cs"
Inherits="SourcePage" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="textCity" runat="server" Height="59px" Style="z-index: 100;
left: 0px;
position: absolute; top: 0px" Width="397px">New York</asp:TextBox>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click"
Style="z-index: 101;
left: 14px; position: absolute; top: 94px" Text="Button" />
<asp:Label ID="Label1" runat="server" Style="z-index: 102; left: 103px;
position: absolute;
top: 137px" Text="Label" Width="261px"></asp:Label>
<asp:Button ID="Button2" runat="server" OnClick="Button2_Click"
Style="z-index: 104;
left: 13px; position: absolute; top: 133px" Text="Button" />
</div>
</form>
</body>
</html>

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class SourcePage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
Response.Redirect("TargetPage.aspx");
}
public String CurrentCity
{
get
{
return textCity.Text;
}
}
protected void Button2_Click(object sender, EventArgs e)
{
Label1.Text = CurrentCity.ToString();
// This works
}
}



<%@ Page Language="C#" AutoEventWireup="true" CodeFile="TargetPage.aspx.cs"
Inherits="TargetPage" %>
<%@ PreviousPageType VirtualPath="~/SourcePage.aspx" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Height="47px" Style="z-index: 100;
left: 0px;
position: absolute; top: 0px" Text="Label" Width="346px"></asp:Label>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click"
Style="z-index: 102;
left: 7px; position: absolute; top: 64px" Text="Button" />
</div>
</form>
</body>
</html>

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class TargetPage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = PreviousPage.CurrentCity;
// Throws error: Object reference not set to an instance of an
object.
}
protected void Button1_Click(object sender, EventArgs e)
{
Response.Redirect("SourcePage.aspx");
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,066
Latest member
VytoKetoReviews

Latest Threads

Top