Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using Style Sheets against components in ASP.NET web forms ? 3

Status
Not open for further replies.

StevenK

Programmer
Jan 5, 2001
1,294
0
0
GB
I've developed a series of web forms for a simple web-based application.
Due to the nature of it I'd like to be able to make use of style sheets - rather than having to change the look and feel of each component in turn (tedious and high error-potential).
Can anyone enlighten me as to how I hook up the component(s) to the required style sheet.
The 'StyleSheet' property against some of the components (labels, textboxes, etc.) doesn't seemingly have have an impact on the resultant pages.
Do I need to do something more ?
Any help would be appreciated.
Thanks in advance
Steve
 
style sheet works well with all controls. all the things u need to do is make a css file,create various class within it.and then use those classes in various controls(labels,textboxes etc.)
make sure that u have used classes in control declarations.

Rakhi
 
I'm still at a loss with this.
Do I need a separate style sheet for each style ?
I thought the idea was that the style sheet(s) contained a number of different styles and depending on tags, the right style would be used in the resultant page.
Can anyone give me a simple walk-through or example ?
Thanks again.
Steve
 
Styles.css
Code:
.funkyBox
{
	border-right: #000099 thin solid;
	padding-right: 4px;
	border-top: #000099 thin solid;
	padding-left: 4px;
	font-size: x-small;
	padding-bottom: 4px;
	border-left: #000099 thin solid;
	padding-top: 4px;
	border-bottom: #000099 thin solid;
	background-color: #ccffcc;
	text-align: center;
}

aspx
Code:
<html>
<head>
<link href="Styles.css" type="text/css" rel="stylesheet">
</head>
<body>
<form runat="server">

<asp:Label runat="server" CssClass="funkyBox">
Test
</asp:Label>
</form>
</body>
</html>

Greetings,
Dragonwell
 
So far so good ....
I've worked away on this and am able to get components on a web form connected up to a style sheet (Labels and standard text on the web form).
However how can I set up a number of different component types to point to different styles within this style sheet. I.e. I want TextBox's to be one style (ie. Verdana font), Labels to be another (i.e. Wingdings), etc.
Is this acheivable - and if so how ?
Thanks so far.
Steve
 
In your stylesheet you can define styles per elemets like so:
Code:
BODY
{
	margin-top: 0px;
	margin-left: 0px;
        background-color: #cccccc;
}
A
{
	text-decoration: none;
}
A:hover	
{
	color:	red;
}

but as far as I know you are just limited to stanadard HTML elements. For textboxes you can define a style for INPUT tags, which will also be applied to dropdowns, and list boxes.

Another option would be to derive your own textbox control, by simply creating a composite control that inherited from TextBox, in which you define a specific style attribute.

Greetings,
Dragonwell
 
Does anyone else have any clues as to if / how I can make use of different styles (from one style sheet) for ASP.NET controls like the TextBox, DropDownList, etc. ?
Thanks for your help with this Dragonwell.
Steve
 
You'll just have to look into how everything is rendered, and set up the stylesheet accordingly. For instance, a DropDownList is rendered as a SELECT in the HTML, so if you have:

Code:
<style type="text/css"> 
<!-- 
select { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; border: #000000; border-style: solid; } 
--> 
</style>

You will be able to change the style of your DropDownLists.
 
Thanks to everyone concerned on this one.
I've now got to a point where I'm able to control the look and feel of my ASP.NET web forms.
You're all stars !
Thanks again
Steve
 
Hi, I need some help. How do you apply a style to regular HTML inside of a custom control?

Here is my code

<HEAD>
<link href="styles/title.css" type="text/css" rel="stylesheet">
</HEAD>
<body>
<img src="images/top.jpg">
<div id="navbar2">
<ul>
<li id="li1">
Q Title
<li id="li2">
Title
<li id="li3">
Title
<li id="li4">
Title
<li id="li5" >
Title</li>
</ul>
</div>


</body>

But the style I've defined in the style.css file isnt applied to my text. What am I doing wrong?

Thanks for the help
Cen
 
It may be that the style against the text (in these list items) is being adopted from the custom control rather than the underlying page ?
As such, it may be worth setting the style sheet against the custom control ?
I'm none-too-familiar with custom controls so maybe someone will correct me / shoot me down ?
Steve
 
You'd need to set up a style for div ul li:

DIV UL LI
{
}

...or set up a class for the elements to use.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top