2013-04-08 225 views
0

我想通过在前一页上查找控件(文本框)将文本分配给标签。 该控件已准确找到,但文本无法分配。智能感知不显示“文本”属性。如何获得文本?通过查找控件分配文本

protected void Page_Load(object sender, EventArgs e) 
    { 
     if (!IsPostBack) 
     { 
      Control ctContent = this.PreviousPage.Master.FindControl("MainContent"); 
      Control ct = (TextBox) ctContent.FindControl("TextBox1"); 
      //TextBox t = (TextBox) Page.PreviousPage.Master.FindControl("TextBox1"); 
      Label1.Text = String.Format("This is what you wrote there: {0}",ct.??????); 
     }  
    } 
+0

你的意思是以前的页面? – Oded 2013-04-08 13:50:38

+0

我已重定向到新页面。在新页面上是我想要在初始页面(控件重定向的页面)分配文本框文本的标签。 – adityawho 2013-04-08 13:53:15

+0

您正在查找的控件位于_current_页面上。如果你从另一个页面发布它,它应该在'Forms'集合中,但是如果没有看到用于发布的代码是很难确定的。 – Oded 2013-04-08 13:54:09

回答

0

相反

Control ct = (TextBox) ctContent.FindControl("TextBox1");  

只写

TextBox ct = (TextBox) ctContent.FindControl("TextBox1");