今天在找控件级权限实现方案时找到了网上同志们提供的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);
}