在 Web 表单页面中列出所有更新面板 ClientID
有人知道如何在列表中读出我在页面上拥有的所有 UpdatePanel 客户端 ID 吗?基本上我需要使用 UpdatePanel 类型循环遍历页面中的所有控件,并显示每个控件的 ClientID。
我在此页面上有四个更新面板,我正在使用它
private string LoopUpdatePanel(ControlCollection controlCollection)
{
StringBuilder sb = new StringBuilder();
foreach (Control control in controlCollection)
{
if (control is UpdatePanel)
{
sb.Append(((UpdatePanel)control).ClientID + ", ");
}
if (control.Controls != null)
{
LoopUpdatePanel(control.Controls);
}
}
return sb.ToString();
}
它返回一个空字符串?
Anyone know of a way to read out in a list all of the UpdatePanel Client ID's I have on a page? Basically I need to loop through all controls in the page with a type of UpdatePanel, and display the ClientID for each..
I have four update panels on this page and I am using this
private string LoopUpdatePanel(ControlCollection controlCollection)
{
StringBuilder sb = new StringBuilder();
foreach (Control control in controlCollection)
{
if (control is UpdatePanel)
{
sb.Append(((UpdatePanel)control).ClientID + ", ");
}
if (control.Controls != null)
{
LoopUpdatePanel(control.Controls);
}
}
return sb.ToString();
}
It returns an empty string??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
不确定您使用的是什么语言或您尝试过什么...请给我们一些代码,以便我们知道您尝试过什么,也许我们会发现错误。
但作为示例,这里介绍了如何循环控制。只需使用您想要的属性而不是文本(在您的情况下 ID 值和更新面板)。我相信获取控件的重要部分是遍历整个控件层次结构,这样您就不会错过任何子级、孙级等。
Not sure what language you're using or what you've tried...Please give us some code so we know what you have tried maybe we'll catch the error.
but as an example here's how you'd loop through controls. Just use the properties you want instead of text (in your case Id value and update panels). I believe the important part of acquiring controls is to go through the entire control hierarchy so you don't miss any children, grand children etc.
听起来像是一个正确的逻辑,也许您可能正在搜索一组不同的控件?
您是否尝试过使用调试单步执行并检查 ID?
最后一个循环包含 contentplace 持有者。你可能需要更深入。
这是在 VS2010 上用 c#4.0
HTH尝试过的
Sounds like a proper logic, maybe you might be searching through a different set of controls?
Have you tried to step through using debug and check the IDs?
The last loop contains the contentplace holder. You might have to go deeper.
This was tried on VS2010 with c#4.0
HTH
我认为它是一个包含母版页内容的控件
可能是 c# 4.0 的新手
只需忽略它并使用内循环即可。
只需浏览一下您目前拥有的所有控件并将其全部打印出来即可。
此外,您在那里得到的方法没有正确返回值,您被称为没有返回值的方法,而不是签名,但是当您调用像 LoopUpdatePanel(control.Controls); 这样的方法时
It is a control that contains master page contents I think
Could be new to c# 4.0
Just Ignore it and use inner loop.
Just go through all the controls you have at the moment and print it all out.
Also the method you got up there is not returning values correctly, you are called the method without return values, not the signature but when you call the method like LoopUpdatePanel(control.Controls);