对于简单的案例(琐碎的页面,容器链到rcbModels
从不改变,代码质量不担心),硬编码rcbModels.ClientId
到脚本块节省时间,并完成工作。
function pageLoad()
{
models = $find("panelX_containerY_rcbModels");
}
在其他情况下,生成一个页面范围的客户端控件ID映射到客户端ID的字典。
protected void Page_PreRender(object sender, EventArgs e)
{
ScriptManager.RegisterClientScriptBlock(this, typeof(YourPageClass),
"__BehaviorIds", String.Format(CultureInfo.InvariantCulture, @"
var __BehaviorIds = {{
rcbModels: '{0}',
anotherControl: '{1}',
yetAnotherControl: '{2}'
}};",
rcbModels.ClientID,
anotherControl.ClientID,
yetAnotherControl.ClientID), true);
}
然后,您可以在客户端通过名称访问行为ID。
function pageLoad()
{
models = $find(__BehaviorIds.rcbModels);
anotherControl = $find(__BehaviorIds.anotherControl);
yetAnotherControl = $find(__BehaviorIds.yetAnotherControl);
}
我不明白你的建议。该功能位于Script标签内的更新面板之外。 – 2010-10-05 20:03:23