遇到了两个个很郁闷的问题:

asp.net 2.0 中跨页面传递数据时,可以通过Page.PreviousPage.FindControl来查找源页面的控制,从而能获得前一页面中的相应的值,通过设置按钮的PostBackUrl属性来指定目标页面,目前,PostBackUrl属性的控件只有Botton,LinkBotton,ImageBotton三种,所以要实现跨页面传递,只能用这三个控件.

1**使用了MasterPage的页中,多加了一个form, Page.PreviousPage就是null.所以母版页中只能有一个form,就是多了一个form,让我找了两个多小时,但是,为什么多了一个form,就会这样呢?有点不想不能,但是,以后我会记住了,

2有母版页的页面中查找PreviousPage的方法,下面是一个小小的例子,记录一下今天晚上找错的艰辛

MasterPage.master

<%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="MasterPage" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "​ 

<html xmlns="​ 

<head runat="server">

    <title>无标题页</title>

</head>

<body>

    <form id="form1" runat="server">

        <div>

            <br />

            上面

            <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">

            </asp:ContentPlaceHolder>

            下面</div>

    </form>

</body>

</html>


-------Default3.aspx

<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true"

    CodeFile="Default3.aspx.cs" Inherits="Default3" Title="Untitled Page" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">

    <asp:LinkButton ID="LinkButton1" runat="server" PostBackUrl="~/Default4.aspx">LinkButton</asp:LinkButton>

    <asp:TextBox ID="TextBox1" runat="server" Text="ffff"></asp:TextBox>


</asp:Content>

-----Default4.aspx

<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true"

    CodeFile="Default4.aspx.cs" Inherits="Default4" Title="Untitled Page" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">

    <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>

</asp:Content>

-------Default3.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 Default4 : System.Web.UI.Page

{

    protected void Page_Load(object sender, EventArgs e)

    {

        if (Page.PreviousPage != null)

        {

            if (PreviousPage.IsCrossPagePostBack)

            {

        //当有母版页时,通过这种方法来查找前一页中的控件

                TextBox tb = PreviousPage.Master.FindControl("ContentPlaceHolder1").FindControl("TextBox1") as TextBox;

     //没有母板页时,通过下面的方法来查找前一页中的控件

               // TextBox tb = this.PreviousPage.Master.FindControl("TextBox1") as TextBox;

                this.Label1.Text = tb.Text;

            }

        }

    }

}