473,808 Members | 2,882 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Documentation - PreviousPage

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.ht m

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="Sourc ePage.aspx.cs"
Inherits="Sourc ePage" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitl ed 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">N ew York</asp:TextBox>
<asp:Button ID="Button1" runat="server" OnClick="Button 1_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="Button 2_Click"
Style="z-index: 104;
left: 13px; position: absolute; top: 133px" Text="Button" />
</div>
</form>
</body>
</html>

using System;
using System.Data;
using System.Configur ation;
using System.Collecti ons;
using System.Web;
using System.Web.Secu rity;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Web.UI.W ebControls.WebP arts;
using System.Web.UI.H tmlControls;
public partial class SourcePage : System.Web.UI.P age
{
protected void Page_Load(objec t sender, EventArgs e)
{
}
protected void Button1_Click(o bject sender, EventArgs e)
{
Response.Redire ct("TargetPage. aspx");
}
public String CurrentCity
{
get
{
return textCity.Text;
}
}
protected void Button2_Click(o bject sender, EventArgs e)
{
Label1.Text = CurrentCity.ToS tring();
// This works
}
}

<%@ Page Language="C#" AutoEventWireup ="true" CodeFile="Targe tPage.aspx.cs"
Inherits="Targe tPage" %>
<%@ PreviousPageTyp e VirtualPath="~/SourcePage.aspx " %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitl ed 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="Button 1_Click"
Style="z-index: 102;
left: 7px; position: absolute; top: 64px" Text="Button" />
</div>
</form>
</body>
</html>

using System;
using System.Data;
using System.Configur ation;
using System.Collecti ons;
using System.Web;
using System.Web.Secu rity;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Web.UI.W ebControls.WebP arts;
using System.Web.UI.H tmlControls;
public partial class TargetPage : System.Web.UI.P age
{
protected void Page_Load(objec t sender, EventArgs e)
{
Label1.Text = PreviousPage.Cu rrentCity;
// Throws error: Object reference not set to an instance of an
object.
}
protected void Button1_Click(o bject sender, EventArgs e)
{
Response.Redire ct("SourcePage. aspx");
}
}
Jun 6 '06 #1
1 1271
To use PreviousPage you need to use cross page postbacks via <asp:Button
PostBackUrl="Pa ge2.aspx"> or use Server.Transfer . Response.Redire ct won't
do what you want.

-Brock
http://staff.develop.com/ballen
Jun 7 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
3317
by: Alan Silver | last post by:
Hello, I'm doing a cross page post, and want to pick up information from the previous page. The problem is that the previous page contains a user control that is loaded into a Placeholder at run time. I can't seem to get at the Placeholder from the target page. The first page has an empty placeholder, and the code-behind loads a user control dynamically and adds it to the placeholder. The user control grabs an ID from the querystring...
3
1313
by: Kel Good | last post by:
I'm wondering if the PreviousPage property is only populated when a page is cross posted on the same server, or will this work in a web farm situation. Thanks. Kel
1
2557
by: michael.neel | last post by:
Here is the setup: I have an SQL driven sitemap provider - when the user clicks on a database generated link - /Site/DBPages/Article1.aspx - a handler does a Server.Transfer - Server.Transfer("/Site/Template.aspx", true) - to a template page which displays the database related content. The Template page knows it's content because the page does exist in the SQL sitemap provider. The problem comes in with a button on...
2
1737
by: PeterKellner | last post by:
Is there something extra I need to do to make intellisense work when referencing a page class? Here is my working Page_Load from a aspx page. sourcePage does not get it's members listed with intellisense. It acts like it is not a class but compiles fine. Thanks, protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack)
0
1093
by: Jim McGivney | last post by:
I am trying to use the PreviousPage feature in asp.net 2.0 On the source (previous page) I have: protected void Page_Load(object sender, EventArgs e) { ..... Code to populate ArrMH //ArrMH is an array MostHits = ArrMH; } public String MostHits {
4
8568
by: Bryce | last post by:
I have a search page that submits to a search results page. I have set the search results page to be authenticated, so when the user first tries to search, it redirects them to a login screen. When they log in, it goes to the search result screen. But when I do, the PreviousPage variable is null. Once logged in, when I go from the search to the search results screen, PreviousPage is fine. I'm using the authentication built into dot...
1
1340
by: jeroen.bolle | last post by:
I'm trying to pass variables between pages using the post method. I have access to the the page where I've posted my form, but all the objects are empty... An extract of the code: If Not (Page.PreviousPage Is Nothing) Then Label1.Text = "Form sent" If Not (Page.IsCrossPagePostBack) Then If IsNothing(PreviousPage.FindControl("txtVertrek"))
2
2672
by: David C | last post by:
Will the Page.PreviousPage be able to read controls from a non-aspx page, e.g. an html page? Is there a better way to get info. from textboxes/controls? Thanks. David
10
2281
by: rjvrnjn | last post by:
I'm trying to pass a variable value from one page to another. Of all the ways that are available, I like the PreviousPage.FindControl() one as it lets me access the previous page controls and get the value without me being bothered about security et al. But what I find is once the page is posted the only controls that I get in PreviousPage is the master page and none of the controls of the content page are available in PreviousPage.Controls...
0
9721
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10631
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10114
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7651
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6880
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5548
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5686
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4331
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3859
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.