日期:2014-05-18  浏览次数:20424 次

求助大虾们asp使用母版页后控件跨页提交无法找到!!!!在线等
我设置了母版页然后弄了两个页面分别套用母版页,第一个页面有一个textbox1,和button想把textbox1提交到第二个页面,却怎么也无法找到请帮帮我把
第一个页面:
<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
  <div>
  <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
  <asp:Button ID="Button1" runat="server" PostBackUrl="~/Default2.aspx" Text="Button" />
  </div>
</asp:Content> 
第二个页面:
<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" Debug="true"%>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
  <div>  
  </div>
</asp:Content>
第二个页面的代码:
public partial class Default2 : System.Web.UI.Page
{
  protected void Page_Load(object sender, EventArgs e)
  {
  if (Page.PreviousPage != null)
  {
  TextBox s = (TextBox)Page.PreviousPage.FindControl("TextBox1");
  Response.Write(s.Text);
  }
  }
}
提示错误找不到控件、
备注:以下方法也不好用
TextBox s = (TextBox)this.Page.Master.FindControl("MasterPage.master").FindControl("TextBox1");
TextBox txt1=this.Master.FindControl("MainContent").FindControl("TextBox1") as TextBox1 ;
希望大家帮帮我


------解决方案--------------------
If PreviousPage Is Nothing Then
Response.Redirect("otrade.aspx")
Else
'查找在preViousPage(otrade.aspx)的tid.value,一定要一级一级的找下去.先找master,再找contentplacehold,再找TID.
Dim previousPageMaster As MasterPage = PreviousPage.Master
Dim contentPlaceHold As ContentPlaceHolder = previousPageMaster.FindControl("ContentPlaceHolder1")
Dim hiddenField As HiddenField = CType(contentPlaceHold.FindControl("tid"), HiddenField)
ViewState("en_tid") = hiddenField.Value
End If