Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between Class vs CSSClass in ASP.Net CSS + CSS syntax question

Tags:

css

asp.net

What is the difference between:

<asp:GridView CssClass="someclass" 

and

<table class="someclass"> 

And how does it relate to how one defines CSS? For example, using CssClass, one can (I think) write CSS like so:

.someclass {font-family:"arial";           background-color:#FFFFFF;           width: 100%;           font-size: small;}   .someclass th {background: #7AC142;                padding: 5px;               font-size:small;} 

But using class, it seems this syntax doesn't work, and judging from http://www.w3.org/TR/css3-selectors/#class-html I would have to write the above like this:

.someclass {font-family:"arial";           background-color:#FFFFFF;           width: 100%;           font-size: small;}   th.someclass {background: #7AC142;                padding: 5px;               font-size:small;} 

Can someone shed some light on which is the correct way, or if they are both correct, but there is a difference between class and CssClass in ASP.Net?

UPDATE

Ok, looks like they are the same thing....so, are the above syntaxes both correct when using class or cssclass, because they don't seem to be.

like image 606
tbone Avatar asked Jul 29 '09 21:07

tbone


People also ask

What is CssClass in asp net?

ASP.Net CssClass is an abstract wrapper around the css "class" specifier. Essentially, for most intents and purposes, they are the same thing. When you set the CssClass property to some string like "someclass", the html that the WebControl will render will be class = "someclass" .

What is a class style in CSS?

What is a CSS class? A CSS class is an attribute used to define a group of HTML elements in order to apply unique styling and formatting to those elements with CSS.

Does CSS have a class?

CSS syntax contains a selector, and a class is exactly that. It is needed to stylize HTML elements – including changing colors, fonts, or the size of a text. If you want to use a class, use a full stop (.) followed by the class name in a style block.

What is the difference between a class and a cssclass?

Actually, there is a difference between class and CssClass: the class will not be seen by the code behind, but the CssClass will. Thus, if you add a new class to a control in your code behind, for example: When inspecting your rendered element in your browser, you will see that it will be rendered as follows:

Do CSS selectors work with ASP NET classes?

Hope that's clear. Regardless of the way you specify the class for the elements (using ASP.Net's CSSClass, or just setting the class), your CSS selectors will do the same thing. They don't have anything to do with ASP.Net specifically.

What is the difference between cssclass and webcontrol?

Essentially, for most intents and purposes, they are the same thing. When you set the CssClass property to some string like "someclass", the html that the WebControl will render will be class = "someclass".


2 Answers

ASP.Net CssClass is an abstract wrapper around the css "class" specifier.

Essentially, for most intents and purposes, they are the same thing. When you set the CssClass property to some string like "someclass", the html that the WebControl will render will be class = "someclass".


EDIT: The CSS selectors you have written are both "correct", but they do two different things. ".someclass th" matches any descendant th element of an element that has the "someclass" class. The second one matches the th element itself that has the "someclass" class.

Hope that's clear. Regardless of the way you specify the class for the elements (using ASP.Net's CSSClass, or just setting the class), your CSS selectors will do the same thing. They don't have anything to do with ASP.Net specifically.

like image 148
womp Avatar answered Oct 06 '22 02:10

womp


Actually, there is a difference between class and CssClass: the class will not be seen by the code behind, but the CssClass will.

Thus, if you add a new class to a control in your code behind, for example:

myControl.CssClass += " foo"; 

while your control is set as follows:

    <asp:TextBox class="Text" ID="myControl" runat="server" /> 

(Note class attribute: class="Text")

When inspecting your rendered element in your browser, you will see that it will be rendered as follows:

<input class=" foo" name="ctl00$MainContent$myControl" type="text" id="MainContent_myControl" > 

(Note how the class has been overridden: class= " foo".)

If you set the CssClass on the other hand:

<asp:TextBox CssClass="Text" ID="myControl" runat="server" /> 

you will get it rendered (as expected) like so:

<input class="Text foo" name="ctl00$MainContent$myControl" type="text" id="MainContent_myControl"> 

(note the class has now both classes set, as expected! class="Text foo")

like image 20
xypho Avatar answered Oct 06 '22 03:10

xypho