473,385 Members | 1,535 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to get a control on the previous page when it is a content page?

There are 2 pages Default.aspx and Result.aspx:

<!-- Default.aspx -->
<%@ Page Language="C#" AutoEventWireup="true"
MasterPageFile="~/Default.master" CodeFile="Default.aspx.cs"
Inherits="_Default" %>

<asp:Content ID="Content1" runat="server"
ContentPlaceHolderID="ContentPlaceHolder1">
&nbsp;<asp:Label ID="Label1" runat="server" Text="Please input a
string here"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button"
PostBackUrl="~/Result.aspx" /></asp:Content>

//Default.aspx.cs
using System;
using System.Data;
using System.Configuration;
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 _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
}

<!-- Result.aspx -->
<%@ Page Language="C#" MasterPageFile="~/Default.master"
AutoEventWireup="true" CodeFile="Result.aspx.cs" Inherits="Result"
Title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1"
Runat="Server">
<asp:Label ID="Label1" runat="server" Text="The string you input in
the previous page is"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</asp:Content>

//Result.aspx.cs
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 Result : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (PreviousPage != null)
{
TextBox tb = (TextBox)PreviousPage.FindControl("TextBox1");
if (tb != null)
TextBox1.Text = tb.Text;
}
}
}

Both of these 2 pages have the property MasterPageFile set, but the
contents of Default.master is not important. There are 2 controls on
Default.aspx, a TextBox named TextBox1 to accept the input, a button
named Button1 and its PostBackUrl is set to Result.aspx. While
Result.aspx is loading, it tries to get the string the user inputted in
the previous page and shows it in TextBox1.

The problem is after executing the following statement, tb is set to
null:

TextBox tb = (TextBox)PreviousPage.FindControl("TextBox1");

I tried to replace this statement with the following statements:

Content con = (Content)PreviousPage.FindControl("Content1");
if (con == null)
return;

TextBox tb = (TextBox)con.FindControl("TextBox1");

But con is null after executing, so the next statements are ignored.

How can I get TextBox1 on Default.aspx while Result.aspx is loading?
Thanks for any clues.

Regards,
George
Jul 5 '06 #1
0 1509

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

Similar topics

1
by: Mark ??;-\) | last post by:
I would like to display a listing of files on a web page as follows: If there is only one file: display the section name and then display the current file. If there is more than one file (for...
5
by: David Elliott | last post by:
I need a control on a Web Page that can accept an HTML Document and will display it. Any help would be appreciated. Thanks, Dave Here is what I was trying...
2
by: John Lau | last post by:
Hi, Is there documentation that talks about the page lifecycle, the lifecycle of controls on the page, and the rendering of inline code, in a single document? Thanks, John
15
by: Nathan | last post by:
I have an aspx page with a data grid, some textboxes, and an update button. This page also has one html input element with type=file (not inside the data grid and runat=server). The update...
2
by: john | last post by:
Maybe I haven't had that "a-ha" moment yet, but I think the new approach to web projects is a step in the wrong direction. My main beef is that control over the assembly generation process has...
4
by: D | last post by:
Hi I'm obviously still learning here but what I've created is a page with a calendar and button. When I click the button I do a number of tasks and would like to output the progress in messages...
0
by: BillE | last post by:
PROBLEM SUMMARY -- I use "Response.Cache.SetCacheability(HTTPCacheability.NoCache)" to force a page to reload instead of displaying cached content. However, I don't really want to reload the...
7
by: | last post by:
I have what's probably a simple page lifecycle question related to dynamically evaluating values that are placed by a repeater and dynmically placing user controls that use those values. I'm...
2
by: ChrisCicc | last post by:
Hi All, I got a real doozy here. I have read hundreds upon hundreds of forum posts and found numerous others who have replicated this problem, but have yet to find a solution. Through testing I have...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.