How to add CSS in web page in ASP.NET using C#

How to add CSS in web page in ASP.NET using C#


Posted in : ASP.Net Posted on : December 14, 2010 at 6:49 PM Comments : [ 0 ]

In this article we will introduce with how to add CSS in web page in ASP.NET

How to add CSS in web page in ASP.NET using C#

In this example we will introduce how can we add CSS in web page. Right click on solution explorer and click on Add New Item and select stylesheet and click ADD. You can see the following figure.

StyleSheet.css

.tableStyle
{
width: 320px;
height: 211px;
background-color:Teal;
}
.tdStyle
{
width: 50%;
height: 30px;
}
.labelStyle
{
font-family:Verdana;
font-size:small;
font-weight:bold;
}
.firsttdStyle
{
font-size: x-large;
text-align:center;
}
.spanStyle
{
font-family: "Courier New";
}

CSSAdd.aspx (Design Page):

CSSAdd.aspx (source code):

<%@ Page Title="" Language="C#" MasterPageFile="~/RoseindiaMaster.master" 
AutoEventWireup="true"
CodeFile="CSSAdd.aspx.cs" Inherits="CSSAdd" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
<link href="~/Styles/StyleSheet.CSS" type="text/css" rel="Stylesheet" />
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<div>
<h2 style="color: Green">
How to add css in web page in ASP.NET 4, C#</h2>
<table cellpadding="0" cellspacing="0" class="tableStyle">
<tr>
<td class="firsttdStyle" colspan="2">
<strong>User Registration</strong>
</td>
</tr>
<tr>
<td class="tdStyle">
<asp:Label ID="Label1" runat="server" Text="User Name :" CssClass="labelStyle"></asp:Label>
</td>
<td class="tdStyle">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="tdStyle">
<asp:Label ID="Label2" runat="server" Text="Password :" CssClass="labelStyle"></asp:Label>
</td>
<td class="tdStyle">
<asp:TextBox ID="TextBox2" runat="server" TextMode="Password"></asp:TextBox>
</td>
</tr>
<tr>
<td class="tdStyle">
<asp:Label ID="Label3" runat="server" Text="Confirm Password :" CssClass="labelStyle">
</asp:Label>
</td>
<td class="tdStyle">
<asp:TextBox ID="TextBox3" runat="server" TextMode="Password"></asp:TextBox>
</td>
</tr>
<tr>
<td class="tdStyle">
<asp:Label ID="Label4" runat="server" Text="Question :" CssClass="labelStyle"></asp:Label>
</td>
<td class="tdStyle">
<asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="tdStyle">
<asp:Label ID="Label5" runat="server" Text="Answer :" CssClass="labelStyle"></asp:Label>
</td>
<td class="tdStyle">
<asp:TextBox ID="TextBox5" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="tdStyle">
</td>
<td class="tdStyle">
<asp:Button ID="submit_Button" runat="server" Text="Submit" Width="73px" />
&nbsp;<asp:Button ID="cancel_Button" runat="server" Text="Cancel" Width="73px" />
</td>
</tr>
</table>
</div>
</asp:Content>

Output:

Download source code
Go to Topic «PreviousHomeNext»

Your Comment:


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

 
Tutorial Topics