ページ上のすべてのコントロールを検索し、コントロールタイプに基づいてjavascriptコントロール属性を追加できる再帰関数が必要です。
問題は、コントロールのあるいくつかのパネルがあるページがあることです。パネルには、ネストされたパネル/コントロールを含めることもできます。
残念ながら、以下は私が望むことをしませんが、私は似たようなものを探しています...。
Action<Control> traverse = null;
//in a function:
traverse = (ctrl) =>
{
//ctrl.Enabled = false; //or whatever action you're performing
foreach (Control c in ctrl.Controls)
{
Response.Write(c.GetType().ToString() + " : " + c.ID.ToString() + "<br />");
if (c.GetType() == typeof(TextBox))
{
((TextBox)(c)).Attributes["onKeypress"] = "javascript:return FormEdited();";
}
else if (c.GetType() == typeof(DropDownList))
{
((DropDownList)(c)).Attributes["onchange"] = "javascript:return FormEdited();";
}
else if (c.GetType() == typeof(CheckBox))
{
((CheckBox)(c)).Attributes["onClick"] = "javascript:return FormEdited();";
}
}
traverse = (ctrl2) => ctrl.Controls.GetEnumerator();
};