2012-10-12 144 views

回答

1

內容頁

YourControl YourControlObj = this.Master.FindControl("YourControl") as YourControl; 
+0

所行他的工作?我不這麼認爲..!當你寫沒有任何參考的「YourControl」時,它會給出錯誤。 –

0

在母版頁上試試這個 -

<asp:TextBox Id="txt" /> 

在內容頁 -

TextBox t = this.Master.FindControl("txt") as TextBox; 
t.Text = "Some Value"; 
+0

Ritesh它是一個用戶控件。請諮詢 – user576510

+0

我不認爲用戶控件會有什麼不同。 在內容頁面 - 'UControl t = this.Master.FindControl(「uc」)as UControl; //你現在可以使用財產。「# 。 – Ritesh

0

看看這有助於

Literal mpLiteral = (Literal) Master.FindControl("masterPageLiteralControlID"); 
0

做這樣

在母版頁

<uc1:MyWebUserControl ID="myCtl" runat="server" ClientIDMode="Static" /> 

在內容頁面(在後面的代碼)

MyWebUserControl myWCtl = this.Master.FindControl("myCtl") as MyWebUserControl; 
+0

我試圖與此,而是它不會工作: 在主頁: 在內容頁: ShoppingCartControl myWCtl = this.Master.FindControl(」 myCtl「)作爲ShoppingCartControl; 它給錯誤:「類型或命名空間不存在!任何想法? –

相關問題