• 递归控件以加入JS方法


    看到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 == nullcontinue;
                    
    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 == nullcontinue;
                    
    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);
                }

            }
  • 相关阅读:
    day06-Java方法和数组(二)
    day05作业-----------Java方法和数组
    day01作业-------------Java概述
    day04--Java流程控制
    获取数据库连接对象的方法
    oracle数据库时间的处理
    把页面获得的String格式的时间转换成date存入到数据库
    复选下拉菜单
    log4j实现日志记录(搬运)
    js点击按钮打开下拉菜单,再次点击关闭的简单办法
  • 原文地址:https://www.cnblogs.com/syveen/p/231987.html
Copyright © 2020-2023  润新知