PROGRAM NO 1: WRITE A PROGRAM TO SHOW THE USE OF
STANDARD CONTROLS IN A WEB FORM
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
Inherits="_Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.auto-style1
{
width: 103px;
}
.auto-style3
{
width: 165px;
}
.auto-style4
{
width: 143px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<table style="width: 76%;">
<tr>
<td class="auto-style1">
<asp:Label ID="Label1" runat="server" Text="Label">EmployeeName</asp:Label>
</td>
<td class="auto-style4">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</td>
<td class="auto-style3"> </td>
</tr>
<tr>
<td class="auto-style1">
<asp:Label ID="Label2" runat="server" Text="Label">Password</asp:Label>
</td>
<td class="auto-style4">
<asp:TextBox ID="TextBox2" runat="server" TextMode="Password"> </asp:TextBox>
</td>
<td class="auto-style3"> </td>
</tr>
<tr>
<td class="auto-style1">
<asp:Label ID="Label3" runat="server" Text="Label">Address</asp:Label>
</td>
<td class="auto-style4">
<asp:TextBox ID="TextBox3" runat="server" Height="54px" TextMode="MultiLine"
Width="211px"></asp:TextBox>
</td>
<td class="auto-style3"> </td>
</tr>
<tr>
<td class="auto-style1">
<asp:Button ID="Button1" runat="server" Text="Button" />
</td>
<td class="auto-style4">
<asp:LinkButton ID="LinkButton1" runat="server">Submit</asp:LinkButton>
</td>
<td class="auto-style3">
<asp:ImageButton ID="ImageButton1" runat="server" AlternateText="This is Image
Button" ImageUrl="~/logo.gif" BorderColor="Blue" BorderStyle="Solid"
BorderWidth="2px" PostBackUrl="~/Default2.aspx" />
</td>
</tr>
</table>
</form>
</body>
</html>
PROGRAM NO 1 OUTPUT:
PROGRAM NO 2: WRITE A PROGRAM CONTAINING THE LIST
CONTROLS AND ITS FUNCTIONS
<%@ Page Language="VB"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Favorite Movie</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label
id="lblSubjects"
Text="Chose one of the Subject:"
AssociatedControlID="rblSubjects"
Runat="server"
Font-Bold="true"/>
<asp:RadioButtonList
id="rblSubjects"
Runat="server"
Width="285px">
<asp:ListItem
Text="ASP.Net"
Value="subject1"
Selected="True"/>
<asp:ListItem
Text="VB.Net"
Value="subject2" />
<asp:ListItem
Text="Silverlight"
Value="subject3" />
<asp:ListItem
text="Expression Blend"
Value="subject4" />
</asp:RadioButtonList>
<hr />
<br />
<asp:Label
id="Label2"
Text="Chose one of the Degree:"
AssociatedControlID="rblDegree"
Runat="server"
Font-Bold="true"/>
<br />
<asp:RadioButtonList
id="rblDegree"
Runat="server"
Width="285px">
<asp:ListItem
Text="BCA"
Value="degree1" />
<asp:ListItem
Text="MCA"
Value="degree2" />
<asp:ListItem
Text="B.TECH.(IT)"
Value="degree3" />
<asp:ListItem
text="M.TECH.(IT)"
Value="degree4" />
</asp:RadioButtonList>
</div>
</form>
</body>
</html>
PROGRAM NO 2 OUTPUT:
PROGRAM NO 3: WRITE A PROGRAM TO SHOW THE USE OF
FILE AND CALENDER CONTROL
FORNT END:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<p style="text-align: center">
<b></b>
<asp:Label ID="Label1" runat="server" Font-Bold="True" Font-Names="Arial Black"
Font-Size="Medium"
ForeColor="#0066FF">Indian List of Holidays 2009</asp:Label><br /></b>
</p>
<asp:Calendar ID="Calendar1" runat="server" BackColor="#FFFFCC"
BorderColor="#FFCC66"
BorderWidth="1px" DayNameFormat="Shortest" Font-Names="Verdana" Font-
Size="8pt"
ForeColor="#663399" ShowGridLines="True"
OnDayRender="Calendar1_DayRender"
OnSelectionChanged="Calendar1_SelectionChanged"
OnVisibleMonthChanged="Calendar1_VisibleMonthChanged">
<SelectedDayStyle BackColor="#CCCCFF" Font-Bold="True" />
<SelectorStyle BackColor="#FFCC66" />
<TodayDayStyle BackColor="#FFCC66" ForeColor="White" />
<OtherMonthDayStyle ForeColor="#CC9966" />
<NextPrevStyle Font-Size="9pt" ForeColor="#FFFFCC" />
<DayHeaderStyle BackColor="#FFCC66" Font-Bold="True" Height="1px" />
<TitleStyle BackColor="#990000" Font-Bold="True" Font-Size="9pt"
ForeColor="#FFFFCC" />
</asp:Calendar>
<br />
<b></b>
<asp:Label ID="LabelAction" runat="server"></asp:Label><br />
</b>
</div>
</form>
</body>
</html>
BACK END:
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections;
public partial class _Default : System.Web.UI.Page
{
Hashtable HolidayList;
protected void Page_Load(object sender, EventArgs e)
{
HolidayList = Getholiday();
Calendar1.Caption = "Calender - Author: Puran Singh Mehra";
Calendar1.FirstDayOfWeek = FirstDayOfWeek.Sunday;
Calendar1.NextPrevFormat = NextPrevFormat.ShortMonth;
Calendar1.TitleFormat = TitleFormat.Month;
Calendar1.ShowGridLines = true;
Calendar1.DayStyle.Height = new Unit(50);
Calendar1.DayStyle.Width = new Unit(150);
Calendar1.DayStyle.HorizontalAlign = HorizontalAlign.Center;
Calendar1.DayStyle.VerticalAlign = VerticalAlign.Middle;
Calendar1.OtherMonthDayStyle.BackColor = System.Drawing.Color.AliceBlue;
}
private Hashtable Getholiday()
{
Hashtable holiday = new Hashtable();
holiday["1/1/2009"] = "New Year";
holiday["1/5/2009"] = "Guru Govind Singh Jayanti";
holiday["1/8/2009"] = "Muharam (Al Hijra)";
holiday["1/14/2009"] = "Pongal";
holiday["1/26/2009"] = "Republic Day";
holiday["2/23/2009"] = "Maha Shivaratri";
holiday["3/10/2009"] = "Milad un Nabi (Birthday of the Prophet";
holiday["3/21/2009"] = "Holi";
holiday["3/21/2009"] = "Telugu New Year";
holiday["4/3/2009"] = "Ram Navmi";
holiday["4/7/2009"] = "Mahavir Jayanti";
holiday["4/10/2009"] = "Good Friday";
holiday["4/12/2009"] = "Easter";
holiday["4/14/2009"] = "Tamil New Year and Dr Ambedkar Birth Day";
holiday["5/1/2009"] = "May Day";
holiday["5/9/2009"] = "Buddha Jayanti and Buddha Purnima";
holiday["6/24/2009"] = "Rath yatra";
holiday["8/13/2009"] = "Krishna Jayanthi";
holiday["8/14/2009"] = "Janmashtami";
holiday["8/15/2009"] = "Independence Day";
holiday["8/19/2009"] = "Parsi New Year";
holiday["8/23/2009"] = "Vinayaka Chaturthi";
holiday["9/2/2009"] = "Onam";
holiday["9/5/2009"] = "Teachers Day";
holiday["9/21/2009"] = "Ramzan";
holiday["9/27/2009"] = "Ayutha Pooja";
holiday["9/28/2009"] = "Vijaya Dasami (Dusherra)";
holiday["10/2/2009"] = "Gandhi Jayanti";
holiday["10/17/2009"] = "Diwali & Govardhan Puja";
holiday["10/19/2009"] = "Bhaidooj";
holiday["11/2/2009"] = "Guru Nanak Jayanti";
holiday["11/14/2009"] = "Children's Day";
holiday["11/28/2009"] = "Bakrid";
holiday["12/25/2009"] = "Christmas";
holiday["12/28/2009"] = "Muharram";
return holiday;
}
protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{
LabelAction.Text = "Date changed to :" + Calendar1.SelectedDate.ToShortDateString();
}
protected void Calendar1_VisibleMonthChanged(object sender, MonthChangedEventArgs
e)
{
LabelAction.Text = "Month changed to :" + e.NewDate.ToShortDateString();
}
protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
{
if (HolidayList[e.Day.Date.ToShortDateString()] != null)
{
Literal literal1 = new Literal();
literal1.Text = "<br/>";
e.Cell.Controls.Add(literal1);
Label label1 = new Label();
label1.Text = (string)HolidayList[e.Day.Date.ToShortDateString()];
label1.Font.Size = new FontUnit(FontSize.Small);
e.Cell.Controls.Add(label1);
}
}
}
PROGRAM NO 3 OUTPUT:
PROGRAM NO 4: WRITE A PROGRAM TO SHOW THE USE OF
FILE AND CALENDER CONTROL
Advertisement.xml
<?xml version="1.0" encoding="utf-8" ?>
<Advertisements>
<Ad>
<ImageUrl>images/new/computer.jpg</ImageUrl>
<NavigateUrl>http://www.careerride.com</NavigateUrl>
<AlternateText>Desktops</AlternateText>
<Keyword>Computers</Keyword>
<Impressions>80</Impressions>
</Ad>
<Ad>
<ImageUrl>images/new/laptop.jpg</ImageUrl>
<NavigateUrl>http://www.tutorialride.com</NavigateUrl>
<AlternateText>Laptop</AlternateText>
<Keyword>Computers</Keyword>
<Impressions>80</Impressions>
</Ad>
<Ad>
<ImageUrl>images/new/books.jpg</ImageUrl>
<NavigateUrl>http://www.tutorialride.com</NavigateUrl>
<AlternateText>Books</AlternateText>
<Keyword>Books</Keyword>
<Impressions>80</Impressions>
</Ad>
</Advertisements>
Ad-rotator.aspx
<!DOCTYPE html>
<script language="VB" runat="server">
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Advertisement Page</title>
</head>
<body>
<h3>AdRotator Example</h3>
<form id="form1" runat="server">
<asp:AdRotator id="ar1" AdvertisementFile="Advertisement.xml"
BorderWidth="1" runat=server />
</form>
</body>
</html>
PROGRAM NO 4 OUTPUT:
PROGRAM NO 5: WRITE A PROGRAM TO CREATE AN
ADMISSION FORM FOR COLLEGE
WebControls.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebControls.aspx.cs"
Inherits="WebFormsControlls.WebControls" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.auto-style1 {
width: 100%;
}
.auto-style2 {
width: 278px;
}
.auto-style3 {
width: 278px;
height: 23px;
}
.auto-style4 {
height: 23px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<table class="auto-style1">
<tr>
<td>
<asp:Label ID="Label1" runat="server" Text="User Name"></asp:Label>
</td>
<td>
<asp:TextBox ID="username" runat="server" required="true"></asp:TextBox></td>
</tr>
<tr>
<td>
<asp:Label ID="Label6" runat="server" Text="Email ID"></asp:Label>
</td>
<td>
<asp:TextBox ID="EmailID" runat="server" TextMode="Email"></asp:TextBox></td>
</tr>
<tr>
<td>
<asp:Label ID="Label2" runat="server" Text="Password"></asp:Label></td>
<td>
<asp:TextBox ID="TextBox2" runat="server"
TextMode="Password"></asp:TextBox></td>
</tr>
<tr>
<td>
<asp:Label ID="Label3" runat="server" Text="Confirm Password"></asp:Label></td>
<td>
<asp:TextBox ID="TextBox3" runat="server"
TextMode="Password"></asp:TextBox></td>
</tr>
<tr>
<td>
<asp:Label ID="Label4" runat="server" Text="Gender"></asp:Label></td>
<td>
<asp:RadioButton ID="RadioButton1" runat="server" GroupName="gender" Text="Male"
/>
<asp:RadioButton ID="RadioButton2" runat="server" GroupName="gender"
Text="Female" /></td>
</tr>
<tr>
<td>
<asp:Label ID="Label5" runat="server" Text="Select Course"></asp:Label>s</td>
<td>
<asp:CheckBox ID="CheckBox1" runat="server" Text="J2SEE" />
<asp:CheckBox ID="CheckBox2" runat="server" Text="J2EE" />
<asp:CheckBox ID="CheckBox3" runat="server" Text="Spring Framework" />
</td>
</tr>
<tr>
<td>
</td>
<td>
<br />
<asp:Button ID="Button1" runat="server" Text="Register" CssClass="btn btn-primary"
OnClick="Button1_Click"/>
</td>
</tr>
</table>
<asp:Label ID="message" runat="server" Font-Size="Medium"
ForeColor="Red"></asp:Label>
</div>
</form>
<table class="auto-style1">
<tr>
<td class="auto-style2"><asp:Label ID="ShowUserNameLabel" runat="server"
></asp:Label></td>
<td>
<asp:Label ID="ShowUserName" runat="server" ></asp:Label></td>
</tr>
<tr>
<td class="auto-style2"><asp:Label ID="ShowEmailIDLabel" runat="server"
></asp:Label></td>
<td>
<asp:Label ID="ShowEmail" runat="server" ></asp:Label></td>
</tr>
<tr>
<td class="auto-style3"><asp:Label ID="ShowGenderLabel" runat="server"
></asp:Label></td>
<td class="auto-style4">
<asp:Label ID="ShowGender" runat="server" ></asp:Label></td>
</tr>
<tr>
<td class="auto-style2"><asp:Label ID="ShowCourseLabel" runat="server"
></asp:Label></td>
<td>
<asp:Label ID="ShowCourses" runat="server" ></asp:Label></td>
</tr>
</table>
</body>
</html>
PROGRAM NO 5 OUTPUT:
PROGRAM NO 6: WRITE A PROGRAM TO DEMONSTRATE
MASTER PAGE
<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site1.master.cs"
Inherits="masterpage.Site1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>c# corner</title>
<link href="css/my.css" rel="stylesheet" />
<asp:ContentPlaceHolder ID="head" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<!DOCTYPE html>
<html>
<head>
<title>my layout</title>
<link rel="stylesheet" type="text/css" href="my.css">
</head>
<body>
<header id="header">
<h1>c# corner</h1>
</header>
<nav id="nav">
<ul>
<li><a href="home.aspx">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Article</a></li>
<li><a href="#">Contact</a></li>
</ul>
</nav>
<aside id="side">
<h1>news</h1>
<a href="#"><p>creating html website</p></a>
<a href="#"><p>learn css</p></a>
<a href="#">learn c#</a>
</aside>
<div id="con">
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</div>
<footer id="footer">
copyright @c# corner
</footer>
</body>
</html>
<form id="form1" runat="server">
</form>
</body>
</html>
Home.aspx
<%@ Page Title="" Language="C#" MasterPageFile="~/Site1.Master"
AutoEventWireup="true" CodeBehind="home.aspx.cs" Inherits="masterpage.home" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1"
runat="server">
<h1>Home page</h1>
</asp:Content>
PROGRAM NO 6 OUTPUT:
PROGRAM NO 7: WRITE A PROGRAM TO DEMONSTRATE A
LOGIN PAGE WITH AUTHENTICATION FOR USER
FRONTEND
<form id="form1" runat="server">
<div>
<asp:Login ID="Login1" runat="server" BackColor="#F7F7DE" BorderColor="#CCCC99"
BorderStyle="Solid" BorderWidth="1px" Font-Names="Verdana" Font-Size="10pt">
<TitleTextStyle BackColor="#6B696B" Font-Bold="True" ForeColor="#FFFFFF" />
</asp:Login>
</div>
</form>
.LoginControl
{
background-color:#F7F7DE;
border-color:#CCCC99;
border-style:solid;
border-width:1px;
font-family:Verdana;
font-size:10px;
}
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Login Control</title>
<link href="StyleSheet.css" type="text/css" rel="Stylesheet" />
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Login ID="Login1" runat="server" CssClass="LoginControl">
<TitleTextStyle BackColor="#6B696B" Font-Bold="True" ForeColor="#FFFFFF" />
</asp:Login>
</div>
</form>
</body>
</html>
<asp:Login ID="Login1" runat="server" CssClass="LoginControl"
CreateUserText="Register"
CreateUserUrl="~/Register.aspx"
HelpPageText="Additional Help" HelpPageUrl="~/Help.aspx"
InstructionText="Please enter your user name and password for login.">
<TitleTextStyle BackColor="#6B696B" Font-Bold="True" ForeColor="#FFFFFF" />
</asp:Login>
BACKEND
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
ViewState["LoginErrors"] = 0;
}
protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
{
if (YourValidationFunction(Login1.UserName, Login1.Password))
{
// e.Authenticated = true;
Login1.Visible = false;
MessageLabel.Text = "Successfully Logged In";
}
else
{
e.Authenticated = false;
}
}
protected void Login1_LoginError(object sender, EventArgs e)
{
if (ViewState["LoginErrors"] == null)
ViewState["LoginErrors"] = 0;
int ErrorCount = (int)ViewState["LoginErrors"] + 1;
ViewState["LoginErrors"] = ErrorCount;
if ((ErrorCount > 3) && (Login1.PasswordRecoveryUrl != string.Empty))
Response.Redirect(Login1.PasswordRecoveryUrl);
}
private bool YourValidationFunction(string UserName, string Password)
{
bool boolReturnValue = false;
string strConnection = "server=.;database=Vendor;uid=sa;pwd=wintellect;";
SqlConnection sqlConnection = new SqlConnection(strConnection);
String SQLQuery = "SELECT UserName, Password FROM Login";
SqlCommand command = new SqlCommand(SQLQuery, sqlConnection);
SqlDataReader Dr;
sqlConnection.Open();
Dr = command.ExecuteReader();
while (Dr.Read())
{
if ((UserName == Dr["UserName"].ToString()) & (Password ==
Dr["Password"].ToString()))
{
boolReturnValue = true;
}
Dr.Close();
return boolReturnValue;
}
return boolReturnValue;
}
}
PROGRAM NO 7 OUTPUT:
PROGRAM NO 8: WRITE A PROGRAM TO DEMONSTRATE
REQUIRED FIELD VALIDATOR
FRONTEND
<form id="form1" runat="server">
Your name:<br />
<asp:TextBox runat="server" id="txtName" />
<asp:RequiredFieldValidator runat="server" id="reqName" controltovalidate="txtName"
errormessage="Please enter your name!" />
<br /><br />
<asp:Button runat="server" id="btnSubmitForm" text="Ok" />
</form>
<asp:Button runat="server" id="btnSubmitForm" text="Ok"
onclick="btnSubmitForm_Click" />
BACKEND
protected void btnSubmitForm_Click(object sender, EventArgs e)
{
if(Page.IsValid)
{
btnSubmitForm.Text = "My form is valid!";
}
}
PROGRAM NO 8 OUTPUT: