首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

有没有人了解asp.net里的FindControl的实现原理?该如何处理

2012-01-13 
有没有人了解asp.net里的FindControl的实现原理?最近期望实现一个类似FindControl的方法,但想找到的不是服

有没有人了解asp.net里的FindControl的实现原理?
最近期望实现一个类似FindControl的方法,但想找到的不是服务器控件对象,而是像{$Title}等这样的标签,并对它进行相关的替换.

[解决办法]
考虑把文件内容取出来给一字符串变量,然后Replace,再写回文件
[解决办法]
以下是Reflector输出的:

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);
}
[解决办法]
string.Replace
StringBuilder.Replace
Regex.Replace

都可以
[解决办法]
用sp1234的方法
使用Reflector,看看MS的代码就行了
能学到好多东西的
[解决办法]
页面中应该是维护着一个控件集合,这样通过键值也就是名字就很容易找到指定的控件了

热点排行