0% found this document useful (0 votes)
36 views

AWP Practical Practice Worksheet

The document describes an assignment to create ASP.NET web forms with various server controls. It includes code snippets for: 1) A registration form with validation controls to validate fields like name, password, email, age on submit. 2) A web form with radio buttons and dropdown lists to change label formatting based on selections. 3) Another form demonstrating setting properties of controls like textboxes, checkboxes, dropdown lists, and displaying output on a button click.

Uploaded by

Ankit Singh
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views

AWP Practical Practice Worksheet

The document describes an assignment to create ASP.NET web forms with various server controls. It includes code snippets for: 1) A registration form with validation controls to validate fields like name, password, email, age on submit. 2) A web form with radio buttons and dropdown lists to change label formatting based on selections. 3) Another form demonstrating setting properties of controls like textboxes, checkboxes, dropdown lists, and displaying output on a button click.

Uploaded by

Ankit Singh
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Advanced Web Programming

Practical Practice Worksheet


Name Ankit Ramlaxman Singh Roll Number 20302C0062
Subject/Course: Advanced Web Programming
Topic Working with ASP .NET

1. Working with ASP .NET

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" />
&nbsp;<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&amp;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");
}
}

protected void Button1_Click(object sender, EventArgs e)


{
if (ChkBold.Checked == true)
lblmsg.Font.Bold = true;
else
lblmsg.Font.Bold = false;

if (ChkItalic.Checked == true)
lblmsg.Font.Italic = true;

Vidyalankar School of Information Technology


else
lblmsg.Font.Italic = false;

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 :-

Vidyalankar School of Information Technology


2) Design an asp.net webpage with 2 groups of Radio Buttons, DropDownList, label and TextBox to
perform the following operations: -
a. On click of Radio Buttons each at the same time from two different groups, change the font- size
and font-face of the label’s Text.
b. Also, on the same webpage show that, on selecting a country name from the dropdown list, its
respective country code gets displayed in a textbox.
Vidyalankar School of Information Technology
3) Create a registration form having text fields for accepting Username, Age, Email, Address and Mobile
number. Perform the following validations for the same:
a) All fields need to be filled compulsorily
b) Username should contain only alphabets and should not be more than 25 characters long
c) Validate email and mobile number appropriately
d) Age should be between 18 and 32 only.
Include submit and cancel buttons. On click of submit button, open a new page and display all the
information entered by the user and on click of cancel button, all text fields should be cleared.

WebForm1.aspx :-
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs"
Inherits="Validate.WebForm1" %>

<!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></title>
</head>
<body>
<form id="form1" runat="server">
<div>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Registration Form<br />

Name :&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&
nbsp;&nbsp;&nbsp;
<asp:TextBox ID="TxtName" runat="server"></asp:TextBox>
&nbsp;&nbsp;&nbsp; <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server"
ControlToValidate="TxtName" ErrorMessage="Enter your Name"
ForeColor="Red"></asp:RequiredFieldValidator>
<br />
Password :&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:TextBox ID="TxtPWD" runat="server" TextMode="Password"></asp:TextBox>
&nbsp;&nbsp;&nbsp; <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>
&nbsp;&nbsp;&nbsp; <asp:CompareValidator ID="CompareValidator1" runat="server"
ControlToCompare="TxtPWD" ControlToValidate="TxtCompPwd" ErrorMessage="Password does not match"
ForeColor="Red"></asp:CompareValidator>
<br />
Email
ID :&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:TextBox ID="TxtEmail" runat="server"></asp:TextBox>
&nbsp;&nbsp;&nbsp; <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
ControlToValidate="TxtEmail" ErrorMessage="Enter Valid E-mail" ForeColor="Red"
ValidationExpression="&quot;\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*&quot;"></
asp:RegularExpressionValidator>
<br />

Age :&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n

Vidyalankar School of Information Technology


bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:TextBox ID="TxtAge" runat="server"></asp:TextBox>
&nbsp;&nbsp;&nbsp; <asp:RangeValidator ID="RangeValidator1" runat="server" ControlToValidate="TxtAge"
ErrorMessage="Age is not between 18-32" ForeColor="Red" MaximumValue="32" MinimumValue="18"
Type="Integer"></asp:RangeValidator>
<br />
User
ID :&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:TextBox ID="TxtUserID" runat="server"></asp:TextBox>
&nbsp;&nbsp;&nbsp; <asp:CustomValidator ID="CustomValidator1" runat="server"
ControlToValidate="TxtUserID" Display="Dynamic" EnableViewState="False" ErrorMessage="Enter atleast
single Capital &amp;amp; Lower Case Letter &amp;amp; a Digit &amp;amp; Length shld be between 6-25"
onservervalidate="CustomValidator1_ServerValidate" ForeColor="Red"
ValidateEmptyText="True"></asp:CustomValidator>
<br />
<br />
<asp:ValidationSummary ID="ValidationSummary1" runat="server" HeaderText="Validation
Summary" Height="80px" ShowMessageBox="True" Width="278px" />
<br />
<asp:Label ID="LblMsg" runat="server" Text="Label"></asp:Label>
<br />
<br />
<asp:Button ID="Submit" runat="server" OnClick="Submit_Click" OnClientClick="Button1_Click"
Text="Submit" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:Button ID="Cancel" runat="server" OnClientClick="Cancel_Click" Text="Cancel" />
</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 Validate
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

protected void Submit_Click(object sender, EventArgs e)


{
if (Page.IsValid)
{
LblMsg.Text = "This is a valid form";
}
}
protected void Cancel_Click(object sender,EventArgs e)
{

Vidyalankar School of Information Technology


LblMsg.Text = "No attempt was made to validate this form.";
}
protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
{
string str = args.Value;
args.IsValid = false;
if(str.Length <6 || str.Length>25)
{
return;
}

bool capital = false;


foreach(char ch in str)
{
if(ch>='A' && ch<='Z')
{
capital = true;
break;
}
}
if(!capital)
{
return;
}

bool lower = false;


foreach(char ch in str)
{
if(ch>='a' && ch<='z')
{
lower = true;
break;
}
}
if(!lower)
{
return;
}
bool digit = false;
foreach(char ch in str)
{
if(ch>='0' && ch<='9')
{
digit = true;
break;
}
}
if(!digit)
{
return;
}
args.IsValid = true;
}
}
}

Vidyalankar School of Information Technology


Output :-

4) Display the no. of visitors on a given web page.


5) Write a program to create a DLL to print a factorial of a number.
6) Create a simple web page to display the Date properties (year, month, day, hour, minute, second,
millisecond etc.) as well as to display the number of days of the year between two specified years.
7) Create Web Form to demonstrate use of User Control. Create header named user control having
company name and use it in a webpage.
8) Create a simple web page to count the number of times the current webpage is submitted to the server
onclick event of a Button

Vidyalankar School of Information Technology

You might also like