1
我有一個asp頁面的主頁和ContentPlaceHolder 我想找到所有控件(複選框,文本框,標籤,...)在我的頁面 我這樣做(沒有masterpage )正常獲取控件在ContentPlaceHolder asp.net與每個
Dim c As Control
For Each c In Page.Controls
For Each childc In c.Controls
If CType(childc, TextBox).Text <> "" Then
但是這個代碼不與母版 回答我不怎麼一回事,因爲我希望所有的控件,需要此代碼
TextBox TB=Master.FindControl("ContentPlaceHolder1").FindControl("textbox1") as TextBox;
您可以從FindControl(「ContentPlaceHolder1」)。Controls'開始,而不是'Page.Controls'開始。但是這不適用於嵌套控件(比如在「Panel」或者「GridView」中)。你爲什麼需要它。在正確的位置搜索,而不是循環所有子控件。 – 2014-10-18 21:33:46
謝謝我有約60控制(文本框,DRP,CHK,...)和數據庫我想要的時候,用戶點擊發送按鈕從這個for-loop搜索所有控制和保存數據庫中的值我做的沒有正確的masterpage,但我不能做現在我測試你的解決方案和chane page.control,但視覺工作室說錯誤「對象引用未設置爲對象的實例」 – user1670642 2014-10-19 05:07:59