如何从 asp:panel 获取文本属性
可能是一个简单的问题,但我已经浏览了 30 分钟,但仍然找不到解决方案!
我有一个面板,它有一个属性 text="something"。但面板类似乎没有 getAttribute 方法...我个人认为这是愚蠢的!
代码如下:
foreach (Control c in clientGrid.Controls)
{
if (c.GetType().ToString().Equals("System.Web.UI.WebControls.Panel"))
{
/*Something*/ textInsidePanel = ((Panel)c)./*Somthing*/
}
}
现在我尝试了 AttributeCollection text = ((Panel)c).Attributes
;
和
string text = ((Panel)c).Attributes.toString();
和其他无用的东西......
这应该非常简单!当我检查 chrome 上的元素时,我可以看到面板(以及 div),并且我可以看到那里的文本属性。我可以看到它的价值!但我希望我的 C# 代码具有价值!
请帮忙!
亚历克斯
Probably a simple question, but I've been browsing now for 30 mins and STILL cant find a solution!
i have a panel and it has an attribute text="something". but the panel class does not seem to have a getAttribute method... Which personally, I think is STUPID!
Code follows:
foreach (Control c in clientGrid.Controls)
{
if (c.GetType().ToString().Equals("System.Web.UI.WebControls.Panel"))
{
/*Something*/ textInsidePanel = ((Panel)c)./*Somthing*/
}
}
Now i've tried AttributeCollection text = ((Panel)c).Attributes
;
and
string text = ((Panel)c).Attributes.toString();
and other useless things...
This should be really simple! when i inspect element on chrome, I can see the panel, (well the div) and i can see the text attribute right there. and i can see its value! but i want my c# code to have the value to!!
Please Help!
Alex
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果我答对了你的问题 - 你可以使用下一个代码
asp 部分
c# 部分 -
if I get you question right - you can use next code
asp part
c# part -
您是否尝试过使用访问器?:
这应该获得属性的值但是我很确定您正在做的事情是不可能的,因为属性值在回发之间不会保留(至少在通过设置时不会保留)客户端脚本)。为此,您应该使用隐藏输入或其他一些表单元素。
Have you tried using an accessor?:
That should get the attribute's value BUT I'm pretty sure what you are doing isn't possible as attribute values are not persisted between postbacks (at least not when set via a client script). To do that you should use hidden inputs or some other form element.
Panel 控件本身没有文本属性。但是,如果您将内部文本作为 LiteralControl 访问,它将起作用:
The Panel control itself doesn't have a text property. But if you access the inner text as a LiteralControl it will work: