user287745
user287745

Reputation: 3161

can css be applied to controls of the page.aspx?

Can css be applied to controls of the page.aspx?

To anything and everything?

Upvotes: 1

Views: 65

Answers (3)

Guffa
Guffa

Reputation: 700172

Yes, and no.

You can't style server controls, as they never reach the browser, but you can style the HTML code that is rendered from the controls.

The server controls in the .aspx source only exist on the server while rendering the page. What's left of the controls when the page is sent to the browser is only the HTML code that the controls are rendered as. For example, a TextBox control renders as an input or textarea element.

You can use CSS to style the elements that the controls render, but for that you need something to target the element. You can for example specify a CssClass value for a control which will be rendered as a class attribute in the HTML code. Another alternative is to specify a class or an id on the surrounding element.

The ID of a server control is however not useful for targeting the elements in CSS. Whenever a control is within a container (like a PlaceHolder or Repeater), it's identity is prepended with the container name to keep identities unique.

Upvotes: 3

Bryan Denny
Bryan Denny

Reputation: 27596

You may also want to consider Themes and Skins for asp.net.

Otherwise use the CssClass property on the control.

<asp:Button ID="Button1" CssClass="CSS_class_here" runat="server" Text="Click me" />

Upvotes: 1

Diodeus - James MacFarlane
Diodeus - James MacFarlane

Reputation: 114347

If you give each element a CSS class name, then yes.

Upvotes: 0

Related Questions