AWP Practical Practice Worksheet
AWP Practical Practice Worksheet
1) Create a simple web page with various sever controls to demonstrate setting and use of their
properties.
a. On click of a button control display the selected items from the listbox in a textbox. Also in the
same webpage display the name of the selected item from the DropDownList1 in a label. Also
change the font size of the same label according to the font size selected from the
Dropdownlist2.
b. Display Image control for photo.
c. Check Boxes provides special formatting (viz. underline, bold, italic) and Radio Buttons
provides color for label.
WebForm1.aspx :-
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs"
Inherits="servercontrol.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
Enter Your Name :
<asp:TextBox ID="TxtName" runat="server" AutoPostBack="True"></asp:TextBox>
<br />
Enter Your Message :
<asp:TextBox ID="TxtMsg" runat="server" AutoPostBack="True" Height="53px"
TextMode="MultiLine" Width="167px"></asp:TextBox>
<br />
Select : <asp:CheckBox ID="ChkBold" runat="server" AutoPostBack="True" Text="BOLD" />
<asp:CheckBox ID="ChkItalic" runat="server" AutoPostBack="True" Text="ITALIC" />
<asp:CheckBox ID="ChkUnderline" runat="server" Text="UNDERLINE" />
<br />
COLOR :
<asp:RadioButton ID="RdbRed" runat="server" AutoPostBack="True" Text="RED" />
<asp:RadioButton ID="RdbGreen" runat="server" AutoPostBack="True" Text="GREEN" />
<asp:RadioButton ID="RdbBlue" runat="server" AutoPostBack="True" Text="BLUE" />
<br />
Choose Font Name
<asp:DropDownList ID="LstFont" runat="server" AutoPostBack="True">
<asp:ListItem>Times New Roman</asp:ListItem>
Vidyalankar School of Information Technology
<asp:ListItem>Arial</asp:ListItem>
<asp:ListItem>Calibri</asp:ListItem>
<asp:ListItem>Vardana</asp:ListItem>
</asp:DropDownList>
<br />
Specify Font Size
<asp:TextBox ID="TxtFontSize" runat="server" AutoPostBack="True"></asp:TextBox>
<br />
Choose Back Color
<asp:DropDownList ID="lstbg" runat="server" AutoPostBack="True">
</asp:DropDownList>
<br />
<asp:CheckBox ID="ChkPic" runat="server" AutoPostBack="True" Text="Add Default Picture" />
<br />
<asp:Image ID="Image1" runat="server" Height="105px" ImageUrl="https://encrypted-
tbn0.gstatic.com/images?q=tbn:ANd9GcQ_dUMt8Wnr53t9bNgMs99PaT8Ei53fU11EPgMJzj96aw&s" Visible="False"
Width="123px" />
<br />
<asp:Label ID="lblmsg" runat="server" BorderStyle="Solid" Text="Label"></asp:Label>
<br />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Display" />
</div>
</form>
</body>
</html>
WebForm1.aspx.cs :-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace servercontrol
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if(!this.IsPostBack)
{
lstbg.Items.Add("White");
lstbg.Items.Add("Yellow");
lstbg.Items.Add("Black");
}
}
if (ChkItalic.Checked == true)
lblmsg.Font.Italic = true;
if (ChkUnderline.Checked == true)
lblmsg.Font.Underline = true;
else
lblmsg.Font.Underline = false;
//updateFontColor
if (RdbRed.Checked == true)
lblmsg.ForeColor = System.Drawing.Color.Red;
else if (RdbGreen.Checked == true)
lblmsg.ForeColor = System.Drawing.Color.Green;
else if (RdbBlue.Checked == true)
lblmsg.ForeColor = System.Drawing.Color.Blue;
//updatefont
lblmsg.Font.Name = LstFont.SelectedItem.Text;
//UpdateFontSize
if(Int32.Parse(TxtFontSize.Text)>0)
{
lblmsg.Font.Size = FontUnit.Point(Int32.Parse(TxtFontSize.Text));
}
//displayimage
if(ChkPic.Checked)
{
Image1.Visible = true;
}
else
{
Image1.Visible = false;
}
//DisplayName&MessageInLable
lblmsg.Text = TxtName.Text + "" + TxtMsg.Text;
}
}
}
Output :-
WebForm1.aspx :-
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs"
Inherits="Validate.WebForm1" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
&
nbsp; Registration Form<br />
Name : &
nbsp;
<asp:TextBox ID="TxtName" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server"
ControlToValidate="TxtName" ErrorMessage="Enter your Name"
ForeColor="Red"></asp:RequiredFieldValidator>
<br />
Password :
<asp:TextBox ID="TxtPWD" runat="server" TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
ControlToValidate="TxtPWD" ErrorMessage="Enter Password" ForeColor="Red"></asp:RequiredFieldValidator>
<br />
Confirm Password :
<asp:TextBox ID="TxtCompPwd" runat="server" TextMode="Password"></asp:TextBox>
<asp:CompareValidator ID="CompareValidator1" runat="server"
ControlToCompare="TxtPWD" ControlToValidate="TxtCompPwd" ErrorMessage="Password does not match"
ForeColor="Red"></asp:CompareValidator>
<br />
Email
ID :
<asp:TextBox ID="TxtEmail" runat="server"></asp:TextBox>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
ControlToValidate="TxtEmail" ErrorMessage="Enter Valid E-mail" ForeColor="Red"
ValidationExpression=""\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*""></
asp:RegularExpressionValidator>
<br />
Age : &n
namespace Validate
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{