看到dudu关于递归控件的方法,想起以前实现过的递归控件以加入JS来将用户的动作写入日志:
private void SetCtlClentProperty(String sSecID,Control ctrl)

{
if(ctrl!=null)

{
foreach (Control obj in ctrl.Controls)

{
if (obj.GetType().ToString() == "System.Web.UI.WebControls.TextBox")
((TextBox)obj).Attributes["onchange"] += "SetPageDataStatus();SetCtrlStatus('"+sSecID+"');";

if (obj.GetType().ToString() == "System.Web.UI.WebControls.Label")
((Label)obj).Attributes["onchange"] += "SetPageDataStatus();SetCtrlStatus('"+sSecID+"');";

if (obj.GetType().ToString() == "System.Web.UI.WebControls.DropDownList" && ((DropDownList)obj).AutoPostBack==false)
((DropDownList)obj).Attributes["onchange"] += "SetPageDataStatus();SetCtrlStatus('"+sSecID+"');";

if (obj.GetType().ToString() == "System.Web.UI.WebControls.DropDownList" && ((DropDownList)obj).AutoPostBack==true)
((DropDownList)obj).Attributes["onchange"] += "SetPageDataStatus();SetCtrlStatus('"+sSecID+"');__doPostBack('"+((DropDownList)obj).ClientID+"','');";
if ((obj.GetType().ToString() == "System.Web.UI.WebControls.CheckBoxList" || obj.GetType().ToString() == "System.Web.UI.WebControls.RadioButtonList" ) && ((CheckBoxList)obj).AutoPostBack==true)

{
for(int k=0;k<((CheckBoxList)obj).Controls.Count;k++)

{
((CheckBox)((CheckBoxList)obj).Controls[0]).Attributes["onclick"] += "SetPageDataStatus();SetCtrlStatus('"+sSecID+"');__doPostBack('"+((CheckBox)((CheckBoxList)obj).Controls[0]).ClientID+"','');";
}
}
if((obj.GetType().ToString() == "System.Web.UI.WebControls.CheckBoxList" || obj.GetType().ToString() == "System.Web.UI.WebControls.RadioButtonList" ) && ((CheckBoxList)obj).AutoPostBack==false)
((CheckBox)((CheckBoxList)obj).Controls[0]).Attributes["onclick"] += "SetPageDataStatus();SetCtrlStatus('"+sSecID+"');";
SetCtlClentProperty(sSecID,obj);
}
}
}


/**//// <summary>
/// Set Control's onchange event;
/// </summary>
/// <param name="oPage">Page object</param>
/// <param name="sCtrlIDs">section ids seperated with ",", like "section1,section2,section3"</param>
private void SetCtlClentProperty(ArrayList oCtrlIDs)

{
foreach (Control oSecID in oCtrlIDs)

{
if (oSecID == null) continue;
if (this._ThisPage.IsPostBack)

{
this._ThisPage.RegisterHiddenField(oSecID.ID,System.Web.HttpContext.Current.Request.Form[oSecID.ID]);
}
else

{
this._ThisPage.RegisterHiddenField(oSecID.ID,"unchanged");
}
SetCtlClentProperty(oSecID.ID,oSecID);
}
}
private void SetCtlClentProperty(ArrayList oCtrlIDs,bool ClearState)

{
foreach (Control oSecID in oCtrlIDs)

{
if (oSecID == null) continue;
if (this._ThisPage.IsPostBack && !ClearState)

{
this._ThisPage.RegisterHiddenField(oSecID.ID,System.Web.HttpContext.Current.Request.Form[oSecID.ID]);
}
else

{
this._ThisPage.RegisterHiddenField(oSecID.ID,"unchanged");
}
SetCtlClentProperty(oSecID.ID,oSecID);
}
}