如何从代码隐藏访问div的类。 [英] How to access a div's class from codebehind.
本文介绍了如何从代码隐藏访问div的类。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在asp.net和c#工作。
我的aspx页面上有一个带有类的div标签,我我想从代码后面访问这个类。我怎么能这样做..
代码:
< div class =something>< br />
//一些代码< br />
< / div>
其中某事是一个css类..我需要在codebehind中访问类。请帮帮我解决这个问题..
解决方案
试试这个链接可以帮助你逐个访问div
http://stackoverflow.com/questions/2766408/how-to -select-an-element-by-class-in-id-in-asp-net [ ^ ]
Als o您可以通过ID访问div,如下所示
< div id = textDiv runat = 服务器 > 您的div文本< / div >
希望这有帮助
由于DIV是一个简单的html控件,你需要让它成为服务器控件。然后你可以访问它的所有属性。
你需要做以下事情:
HTML:
< div id = dvTest runat = server class = 某事 >
//部分代码
< / div >
代码落后:
// 在这里,您可以轻松找到类的值。
string style = dv.Attributes [ class]。ToString();
--Amit
按照此代码分配div的id并使其成为runat =server然后你可以获得这样的CssClass名称。 />
此 .btn.CssClass
I am Working in asp.net and c#.
I have a div tag in my aspx page with a class,I want to access this class from code behind.How can i do it..
CODE:
<div class="something"><br /> //some code<br /> </div>
where something is a css class..I need to access the class something in codebehind.Please help me solve this issue..
解决方案
Try this link which helps you to access div by class
http://stackoverflow.com/questions/2766408/how-to-select-an-element-by-class-instead-of-id-in-asp-net[^]
Also you can access div by id simply like below
<div id="textDiv" runat="server">your div text</div>
Hope this helps
Since DIV is a simple html control, you need to make it server control. Then you can access all the properties of it.
You need to do the following:
HTML:
<div id="dvTest" runat="server" class="something"> //some code </div>
Code behind:
//Here you can find the value of class easily. string style = dv.Attributes["class"].ToString();
--Amit
follow this code assign id of div and make it runat="server" then you can get CssClass name like this.
this.btn.CssClass
这篇关于如何从代码隐藏访问div的类。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文