您可以从后面的代码中为更新面板生成的 div 设置 css 类吗?
如果我有一个 UpdatePanel
<asp:UpdatePanel ID="udPanel" runat="server">
...
</asp:UpdatePanel>
在渲染时创建这个 div
<div id="ctl00_udPanel">
你如何在后面的代码中引用它来动态更改 css 类?
If I have an UpdatePanel
<asp:UpdatePanel ID="udPanel" runat="server">
...
</asp:UpdatePanel>
creates this div when it's rendered
<div id="ctl00_udPanel">
How do you reference this in the code behind to change the css class dynamically?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
你可以做的是在 javascript 中写出 ClientID 客户端,然后使用带有 AddClass(未经测试):
What you could do is write out the ClientID client-side within javascript and then use jQuery with an AddClass (untested):
不幸的是,
UpdatePanel
被认为是浏览器不可见的抽象(但实际上并非如此)。所以你不能对其应用类名。唯一的方法是将类名应用于
UpdatePanel
内的div
或 ASP.NETPanel
。Unfortunately,
UpdatePanel
is considered to be an abstraction that is invisible to the browser (but in reality it isn't). So you can't apply a classname to it.The only way is to apply the classname to a
div
or an ASP.NETPanel
inside theUpdatePanel
.在我的脑海里,尝试
udPanel.Attributes
。From the back of my mind, try
udPanel.Attributes
.这是我能找到的最好的动态执行此操作的方法。您可以创建一个 JavaScript 函数来更改 css 类,该函数接受要更改的控件的 clientID 和 css 类的字符串作为参数。您可以将其设置为在主体的 onload() 方法中调用,动态传入 clientID 和 css 类。这使您能够更改页面不同状态的 css 类。
Here's the best I could find to do this dynamically. You can create a javascript function to change the css class which accepts the clientID of the control to change and a string for the css class as parameters. You can set this to be called in the onload() method of the body dynamically passing in the clientID and the css class. This enables you to change the css class for different states of the page.