Click here to Skip to main content
12,350,971 members (33,083 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: ASP.NET
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">
//some code
</div>


where something is a css class..I need to access the class something in codebehind.Please help me solve this issue..
Posted 17-Feb-13 19:29pm
Comments
Jameel Moideen 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
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

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
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

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

this.btn.CssClass
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 4

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
  Permalink  
v2

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160621.1 | Last Updated 18 Feb 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100