FindControl的源代碼

今天在找控件級權限實現方案時找到了網上同志們提供的FindControl源代碼,留此備用。

另外,以下鏈接是關於在各種情況下用FindControl找控制的資料:http://www.odetocode.com/Articles/116.aspx

 

public   virtual   Control   FindControl(string   id)
{
        return   this.FindControl(id,   0);
}

protected   virtual   Control   FindControl(string   id,   int   pathOffset)
{
        string   text;
        this.EnsureChildControls();
        if   (!this.flags[0x80])
        {
                Control   namingContainer   =   this.NamingContainer;
                if   (namingContainer   !=   null)
                {
                        return   namingContainer.FindControl(id,   pathOffset);
                }
                return   null;
        }


        if   (this.HasControls()   &&   (this._occasionalFields.NamedControls   ==   null))
        {
                this.EnsureNamedControlsTable();
        }


        if   ((this._occasionalFields   ==   null)   ||   (this._occasionalFields.NamedControls   ==   null))
        {
                return   null;
        }


        char[]   anyOf   =   new   char[]   {   '$ ',   ': '   };
        int   num   =   id.IndexOfAny(anyOf,   pathOffset);
        if   (num   ==   -1)
        {
                text   =   id.Substring(pathOffset);
                return   (this._occasionalFields.NamedControls[text]   as   Control);
        }


        text   =   id.Substring(pathOffset,   num   -   pathOffset);
        Control   control2   =   this._occasionalFields.NamedControls[text]   as   Control;
        if   (control2   ==   null)
        {
                return   null;
        }
        return   control2.FindControl(id,   num   +   1);
}

發佈了29 篇原創文章 · 獲贊 14 · 訪問量 3萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章