Click here to Skip to main content
15,171,053 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am Working in 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..


<div class="something"><br />
   //some code<br />

where something is a css class..I need to access the class something in codebehind.Please help me solve this issue..
Updated 3-Aug-21 3:51am
Jameel VM 18-Feb-13 1:35am
what's your requirement?
What do you mean by "accessing a class"? From the standpoint of code behind, this is just a piece of text, and your code behind generated it, if you still did not notice that...

Try this link which helps you to access div by class[^]

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:
<div id="dvTest" runat="server" class="something">
//some code

Code behind:
//Here you can find the value of class easily.
string style = dv.Attributes["class"].ToString();

follow this code assign id of div and make it runat="server" then you can get CssClass name like this.

just do like this :

<div class="something" runat="server" id="test1">

server side code is

string str = test1.Attributes["class"].ToString();

// in the str string u will get class name

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900