0% found this document useful (0 votes)
34 views20 pages

Practical 4 (A, B, C) Awp

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views20 pages

Practical 4 (A, B, C) Awp

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 20

PRACTICAL NO.

4 A

Aim: Create a Registration form to demonstrate use of various Validation controls

CODE:

1] Default.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"


Inherits="_Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<style type="text/css">
.auto-style1 {
width: 100%;
}
.auto-style2 {
width: 343px;
}
.auto-style3 {
width: 343px;
height: 23px;
}
.auto-style4 {
height: 23px;
}
.auto-style5 {
width: 226px;
}
.auto-style6 {
height: 23px;
width: 226px;
}
.auto-style7 {
width: 343px;
height: 27px;
}
.auto-style8 {
width: 226px;
height: 27px;
}
.auto-style9 {
height: 27px;
}
</style>
</head>
<body>
<form id="form2" runat="server">
<div>

<table class="auto-style1">
<tr>
<td class="auto-style2">
<asp:Label ID="Label1" runat="server" Text="Enter Name :
"></asp:Label>
</td>
<td class="auto-style5">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1"
runat="server" ControlToValidate="TextBox1" ErrorMessage="* Name Required"
ForeColor="Red"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="auto-style2">
<asp:Label ID="Label2" runat="server" Text="Enter
Password :"></asp:Label>
</td>
<td class="auto-style5">
<asp:TextBox ID="TextBox2" runat="server"
TextMode="Password"></asp:TextBox>
</td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2"
runat="server" ControlToValidate="TextBox2" ErrorMessage="*Password
Required" ForeColor="Red"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="auto-style2">
<asp:Label ID="Label3" runat="server" Text="Confirm
Password :"></asp:Label>
</td>
<td class="auto-style5">
<asp:TextBox ID="TextBox3" runat="server"
TextMode="Password"></asp:TextBox>
</td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3"
runat="server" ControlToValidate="TextBox3" ErrorMessage="*Password
Required" ForeColor="Red"></asp:RequiredFieldValidator>
<asp:CompareValidator ID="CompareValidator1" runat="server"
ControlToCompare="TextBox2" ControlToValidate="TextBox3"
ErrorMessage="*Enter same password"
ForeColor="Red"></asp:CompareValidator>
</td>
</tr>
<tr>
<td class="auto-style2">
<asp:Label ID="Label4" runat="server" Text="Enter Your Age :
"></asp:Label>
</td>
<td class="auto-style5">
<asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
</td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator4"
runat="server" ControlToValidate="TextBox4" ErrorMessage="*Enter age"
ForeColor="Red"></asp:RequiredFieldValidator>
<asp:RangeValidator ID="RangeValidator1" runat="server"
ControlToValidate="TextBox4" ErrorMessage="*Age required should be between
18 to 40" ForeColor="Red" MaximumValue="40" MinimumValue="18"
Type="Integer"></asp:RangeValidator>
</td>
</tr>
<tr>
<td class="auto-style7">
<asp:Label ID="Label5" runat="server" Text="Enter your Email-
ID :"></asp:Label>
</td>
<td class="auto-style8">
<asp:TextBox ID="TextBox5" runat="server"
TextMode="Email"></asp:TextBox>
</td>
<td class="auto-style9">
<asp:RequiredFieldValidator ID="RequiredFieldValidator5"
runat="server" ControlToValidate="TextBox5" ErrorMessage="*Email ID
required" ForeColor="Red"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1"
runat="server" ControlToValidate="TextBox5" ErrorMessage="*Email ID should
be proper" ForeColor="Red" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\
w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td class="auto-style3">
<asp:Label ID="Label6" runat="server" Text="User
ID :"></asp:Label>
</td>
<td class="auto-style6">
<asp:TextBox ID="TextBox6" runat="server"></asp:TextBox>
</td>
<td class="auto-style4">
<asp:RequiredFieldValidator ID="RequiredFieldValidator6"
runat="server" ControlToValidate="TextBox6" ErrorMessage="*User ID
required" ForeColor="Red"></asp:RequiredFieldValidator>
<asp:CustomValidator ID="CustomValidator1" runat="server"
ControlToValidate="TextBox6" ErrorMessage="*User ID should write properly"
ForeColor="Red"
OnServerValidate="CustomValidator1_ServerValidate"></asp:CustomValidator>
</td>
</tr>
<tr>
<td class="auto-style2">&nbsp;</td>
<td class="auto-style5">
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click"
style="height: 26px" Text="Button" />
</td>
<td>&nbsp;</td>
</tr>
<tr>
<td class="auto-style2">&nbsp;</td>
<td class="auto-style5">
<asp:Label ID="Label7" runat="server"></asp:Label>
</td>
<td>&nbsp;</td>
</tr>

</table>
</div>
</form>
</body>
</html>
2] Default.aspx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page


{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void CustomValidator1_ServerValidate(object source,
ServerValidateEventArgs args)
{
string str = args.Value;

if (str.Length > 3)
{
args.IsValid = true;
}
else
{
args.IsValid = false;
}
}

protected void Button1_Click(object sender, EventArgs e)


{
Label7.Text = "Your registration successful";
}

}
3] web.config

<?xml version="1.0"?>

<!--
For more information on how to configure your ASP.NET application, please
visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->

<configuration>
<appSettings>
<add key="ValidationSettings:UnobtrusiveValidationMode"
value="None"/>
</appSettings>

<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
</system.web>

</configuration>
OUTPUT :
PRACTICAL NO. 4B

Aim: Create Web Form to demonstrate use of Adrotator Control


1] WebForm1.aspx

<%@ Page Language="C#" AutoEventWireup="true"


CodeBehind="WebForm1.aspx.cs" Inherits="practical4badrotator.WebForm1" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>

<asp:AdRotator ID="AdRotator1" runat="server"


DataSourceID="XmlDataSource1" />
<asp:XmlDataSource ID="XmlDataSource1" runat="server"
DataFile="~/XMLFile1.xml"></asp:XmlDataSource>

</div>
</form>
</body>
</html>
2] XMLFile1.xml

<?xml version="1.0" encoding="utf-8" ?>


<Advertisements>
<Ad>
<ImageUrl>computer.jpg</ImageUrl>
<NavigateUrl>http://google.com</NavigateUrl>
<AlternateText>computer</AlternateText>
<Impressions>50</Impressions>
<keyWord>computer</keyWord>
</Ad>
<Ad>
<ImageUrl>flower.jpg</ImageUrl>
<NavigateUrl>http://Youtube.com</NavigateUrl>
<AlternateText>youtube</AlternateText>
<Impressions>30</Impressions>
<keyWord>youtube</keyWord>
</Ad>

</Advertisements>
OUTPUT:
PRACTICAL 4 C

Aim: Create Web Form to demonstrate use User Controls.

Code:

1] WebForm1.aspx

<%@ Page Language="C#" AutoEventWireup="true"


CodeBehind="WebForm1.aspx.cs" Inherits="usercontrol.WebForm1" %>
<%@ Register src="~/WebUserControl1.ascx" TagName="WebUserControl"
TagPrefix="uc1" %>
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click"
Text="Button" />
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<br />
<uc1:WebUserControl ID="WebUserControl1" runat="server" />

</div>
</form>
</body>
</html>

2] 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 usercontrol
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

protected void Button1_Click(object sender, EventArgs e)


{
TextBox2.Text = "Hello Guest: " + TextBox1.Text;
}
}
}
3]WebUserControl1.ascx

<%@ Control Language="C#" AutoEventWireup="true"


CodeBehind="WebUserControl1.ascx.cs"
Inherits="usercontrol.WebUserControl1" %>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click"
Text="Button" />
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>

4] WebUserControl1.ascx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace usercontrol
{
public partial class WebUserControl1 : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{

protected void Button1_Click(object sender, EventArgs e)


{
TextBox2.Text = "Welcome: " + TextBox1.Text;
}
}
}
OUTPUT:

You might also like