xaml にラベルとテキスト ボックスの負荷を定義するフィールドセットがあります。でも。再帰を使用してテキスト ボックスにアクセスできません。
ここに私のxamlのフィールドセットからのスニペットがあります:
<fieldset runat="server" id="fdst1" class="default_form">
<dl>
<dt>
<asp:Label ID="lblCustomerId" Text="Customer ID" runat="server" />
</dt>
<dd>
<asp:TextBox AutoPostBack="true" OnTextChanged="TextBox_OnTextChanged" ID="txtCustomerId"
Enabled="false" runat="server" />
</dd>
</dl>
<dl>
<dt>
<asp:Label ID="Label1" Text="Associated Brand" runat="server" />
</dt>
<dd>
<asp:TextBox AutoPostBack="true" OnTextChanged="TextBox_OnTextChanged" ID="txtBrandName"
Enabled="false" runat="server" />
</dd>
</dl>
テキストボックスコントロールを取得するために使用するコードは次のとおりです...
private List<DropDownList> GetDropDownLists()
{
List<DropDownList> controls = new List<DropDownList>();
FindControls<DropDownList>(this.Controls, controls);
return controls;
}
/// <summary>
/// this will find all the contols in a collection of a given type.
/// </summary>
/// <typeparam name="T">Type of control to find</typeparam>
/// <param name="Controls">Contol Collection to look through</param>
/// <param name="foundControls">List of found controls</param>
public static void FindControls<T>(ControlCollection Controls, List<T> foundControls) where T : class
{
T found = default(T);
if (Controls != null && Controls.Count > 0)
{
for (int i = 0; i < Controls.Count; i++)
{
if (Controls[i] is T)
{
found = Controls[i] as T;
foundControls.Add(found);
break;
}
else
// Recursive method call.
FindControls<T>(Controls[i].Controls, foundControls);
}
}
}
返されるリストは空ですが、ページを渡しています。コントロールが含まれるコントロール コレクション。テーブルを使用する場合、これはすべて正常に機能しますが、上司はそれがフィールドセットにあると主張します。私の質問は、フィールドセットを使用するときに再帰を使用してこれらのテキスト ボックスを取得する方法です。