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 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..
Posted
Updated 3-Aug-21 3:51am
Comments
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...
—SA

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


Code behind:
C#
//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.

C#
this.btn.CssClass
   
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
   
v2

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