c# practical final

68
Q1)Simple Program with C# a) Write a console application that obtains four int values from the user and displays the sum of that four values. using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication3 { class Program { static void Main(string[] args) { int n1, n2,n3,n4, sum; Console.WriteLine("Enter 1st no."); n1 = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("enter 2nd no."); n2 = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Enter 3rd no."); n3 = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Enter 4th no."); n4 = Convert.ToInt32(Console.ReadLine()); sum = n1 + n2 + n3 + n4; Console.WriteLine("\n Sum of four int values are {0}", sum); Console.ReadKey(); } } }

Upload: arundhang

Post on 05-Dec-2015

226 views

Category:

Documents


3 download

DESCRIPTION

C# Practical Final

TRANSCRIPT

Page 1: C# Practical Final

Q1)Simple Program with C#

a) Write a console application that obtains four int values from the user and displays the sum of that four values.

using System;using System.Collections.Generic;using System.Linq;using System.Text;

namespace ConsoleApplication3{ class Program { static void Main(string[] args) { int n1, n2,n3,n4, sum; Console.WriteLine("Enter 1st no."); n1 = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("enter 2nd no."); n2 = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Enter 3rd no."); n3 = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Enter 4th no."); n4 = Convert.ToInt32(Console.ReadLine()); sum = n1 + n2 + n3 + n4; Console.WriteLine("\n Sum of four int values are {0}", sum); Console.ReadKey();

} }}

Page 2: C# Practical Final

Output:

Page 3: C# Practical Final

b) If you have two integers find the Leap year

using System;using System.Collections.Generic;using System.Linq;using System.Text;

namespace leapyear{ class Program { static void Main(string[] args) { int y, r; Console.WriteLine("enter the year"); y=Convert.ToInt32(Console.ReadLine()); r=y%4; if(r==0) { Console.WriteLine("leap year"); } else { Console.WriteLine("not a leap year"); } Console.ReadKey(); } }}

Page 4: C# Practical Final

OUTPUT:-

Page 5: C# Practical Final

c) Write a program to print a Reverse no.using System;using System.Collections.Generic;using System.Linq;using System.Text;

namespace reverse{ class Program { static void Main(string[] args) { int rev=0, n, r; Console.WriteLine("Enter the no."); n = Convert.ToInt32(Console.ReadLine()); while (n > 0) { r = n % 10; rev= rev * 10 + r; n = n / 10; } Console.WriteLine("reverse no.is:-{0}", rev); Console.ReadKey(); } }}

Page 6: C# Practical Final

Output:

Page 7: C# Practical Final

d) Write a console application that places double quotation marks around each word in a string.

using System;using System.Collections.Generic;using System.Linq;using System.Text;

namespace ConsoleApplication3{ class Program { static void Main(string[] args) { string str = "India is my country"; string[]words =str.Split(' '); Console.WriteLine("Given string is :{0},str"); Console.WriteLine("The result is :"); foreach(string word in words) { Console.WriteLine("\"{0}\"",word); } Console.ReadKey(); } }}

Page 8: C# Practical Final

Output:

Page 9: C# Practical Final

g) Write programs using conditional statements and loops:

i. Generate Fibonacci Series

using System;using System.Collections.Generic;using System.Linq;using System.Text;

namespace ConsoleApplication4{ class Program { static void Main(string[] args) { int a = 1, b = 1, i, c, n; Console.WriteLine("Enter how much long series u want to enter"); n = Int32.Parse(Console.ReadLine()); for (i = 0; i <= n; i++) { c = a + b; Console.WriteLine(c); a = b; b = c; } Console.ReadLine(); } }}

Page 10: C# Practical Final

Output:

Page 11: C# Practical Final

ii. Generate various patterns (triangles, diamond and other patterns) with numbers.

using System;using System.Collections.Generic;using System.Linq;using System.Text;

namespace ConsoleApplication3{ class Program { static void Main(string[] args) { int i, j, n; Console.WriteLine("Enter number"); n = Int32.Parse(Console.ReadLine()); for (i = 0; i < n; i++) { for (j = 0; j <= i; j++) { Console.Write("*"); } Console.WriteLine("\n"); } Console.ReadLine(); } }}

Page 12: C# Practical Final

Output:

Page 13: C# Practical Final

iii. Test for prime numbers.

using System;using System.Collections.Generic;using System.Linq;using System.Text;

namespace ConsoleApplication5{ class Program { static void Main(string[] args) { int[] a = { 5, 10 }; int b = 5; try { int x = a[2] / (b - a[0]); } catch (ArithmeticException e) { Console.WriteLine("divide by zero"); } catch (IndexOutOfRangeException e) { Console.WriteLine("Array error"); } finally { Console.WriteLine("finally block execute"); } int y = a[1] / a[0]; Console.WriteLine(y); Console.ReadLine(); } }}

Page 14: C# Practical Final

Output:

Page 15: C# Practical Final

iv.Switch Case

using System;using System.Collections.Generic;using System.Linq;using System.Text;

namespace ConsoleApplication8{

public delegate void EventHandler(); class deleg { public static event EventHandler display; static void Main(string[] args) { display += new EventHandler(Red); display += new EventHandler(Green); display += new EventHandler(Blue); display += new EventHandler(Yellow); display.Invoke(); Console.ReadLine(); } static void Red() { Console.WriteLine("Rose is Red"); } static void Green() { Console.WriteLine("Grass is Green"); } static void Blue() { Console.WriteLine("Sky is Blue"); } static void Yellow() { Console.WriteLine("Lemon is Yellow"); }

Page 16: C# Practical Final

}}

Output:

Page 17: C# Practical Final

vi. Test for vowels.

using System;using System.Collections.Generic;using System.Linq;using System.Text;

namespace ConsoleApplication3{ class Program { static void Main(string[] args) { int a ; char c; Console.WriteLine("Enter any alphabet:"); a = Console.Read(); c = Convert.ToChar(a); switch (c) { case 'a': Console.WriteLine("a is vowel"); break; case 'e': Console.WriteLine("e is vowel"); break; case 'i': Console.WriteLine("i is vowel"); break; case 'o': Console.WriteLine("o is vowel"); break; case 'u': Console.WriteLine("u is vowel"); break; default: Console.WriteLine("it is not vowel"); break; } Console.ReadKey(); } }}

Page 18: C# Practical Final

Output:

Page 19: C# Practical Final

Q2 Object Oriented Program with C#

a)Program Using Classes

using System;using System.Collections.Generic;using System.Linq;using System.Text;

namespace ConsoleApplication2{ public class circle { const float pi = 3.14f; float r = 14.7f; public float area() { return (pi * r * r); } public void circ() { Console.Write((2 * pi * r)); } } class Program { static void Main(string[] args) { circle c = new circle(); Console.Write("Area of circle:"); Console.WriteLine(c.area()); Console.Write("Circumference of circle:"); c.circ(); Console.ReadKey(); } }}

Page 20: C# Practical Final

Output:

Page 21: C# Practical Final

C) Program with different features of C#

Constructor

using System;using System.Collections.Generic;using System.Linq;using System.Text;

namespace ConsoleApplication1{ public class construct { int x; public construct(int a, int b) { Console.WriteLine(a + b); } public construct(float a, float b) { Console.WriteLine(a + b); } public construct() { x = 2; Console.WriteLine(x+x); } } class Program { static void Main(string[] args) { construct c1 = new construct(3, 5); construct c2 = new construct(12.5f,13.2f); construct c3 = new construct(); Console.ReadKey(); } }}

Page 22: C# Practical Final

Output:

Page 23: C# Practical Final

Interface

using System;using System.Collections.Generic;using System.Linq;using System.Text;

namespace ConsoleApplication2{ interface shape { void calculate(float f1, float f2); } class circle : shape { public void calculate(float x, float y) { Console.WriteLine("Circle area:{0}", 3.14f * x * x); } } class rectangle : shape { public void calculate(float x, float y) { Console.WriteLine("rectangle area:{0}",x*y); } } class Program { static void Main(string[] args) { circle c = new circle(); rectangle r = new rectangle(); shape s; s = c; s.calculate(10, 0); s = r; s.calculate(10, 10); Console.ReadKey(); }

Page 24: C# Practical Final

}}

Output:

Page 25: C# Practical Final

Function overloading

using System;using System.Collections.Generic;using System.Linq;using System.Text;

namespace ConsoleApplication3{ class Program { static void sum(int a, int b) { Console.WriteLine(a + b); } static void sum(float a, float b) { Console.WriteLine(a + b); } static void sum(int a) { Console.WriteLine(a + a); } static void Main(string[] args) { sum(2,3); sum(12.3f, 2.4f); sum(4); Console.ReadKey(); } }}

Page 26: C# Practical Final

Output:

Page 27: C# Practical Final

4) Program Using CSS

internalcss.html

<!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> <title>My Page</title> <style type="text/css"> h2,p{color:Red;font-family:Arial;} th{text-align:center;background:green;font-weight:bolder;} td{text-align:center;color:Blue;}</style></head><body><h2>Example of Internal css</h2><table border="1"><tr><th>WST</th><td>CSS</td></tr><tr><th>OOP</th><td>C++</td></tr></table><p>Embedded css is much better than Inline css. Atleast it doesn't mix up with HTML tags to confuse us.</p></body></html>

Page 28: C# Practical Final

Output:

Page 29: C# Practical Final

Externalcss.html

<!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> <title>External Style Sheet</title> <link rel="Stylesheet" type="text/css" href="tyit.css" /></head><body><h2>Example of External css</h2><p>This is a "True Separation" of style and content.</p>

</body></html>

Tyit.css

body {background:black}h2,p{ color:White; font-family:Arial; text-align:center;}h2{ text-transform:uppercase; text-decoration:underline;}th{ text-align:center; background:green; font-weight:bolder;}td

Page 30: C# Practical Final

{ text-align:center; color:Blue;}pi{ color:White; border-style:solid; font-weight:lighter;}

Output:-

Page 31: C# Practical Final

5. Programs using ASP.NET Server controls.

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>

<!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> <script runat="server"> protected void displaySelected(object sender,EventArgs e){ Label1.Text="<b>Selected:</b><br>";foreach(ListItem item in CheckBoxList1.Items){if(item.Selected==true){Label1.Text+=item.Value+"<br>";}}}</script></head>

<body> <form id="form1" runat="server"> <div> <asp:CheckBoxList ID="CheckBoxList1" runat="server" ><asp:ListItem>C#</asp:ListItem><asp:ListItem>VB</asp:ListItem><asp:ListItem>PERL</asp:ListItem><asp:ListItem>PYTHON</asp:ListItem><asp:ListItem>JSCRIPT</asp:ListItem></asp:CheckBoxList><br/><asp:Button ID="Button1" runat="server" Text="Selected" OnClick="displaySelected" /><br/><br/><asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>

Page 32: C# Practical Final

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

Coocki

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Cookies.aspx.cs" Inherits="Cookies" %>

<!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> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <br /> <asp:Button ID="Button1" runat="server" Text="Button" OnClick="getcoo"/> <br /> <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> <br /> </div> </form></body></html>

Page 33: C# Practical Final

Output

Page 34: C# Practical Final

HTML Server Control

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Radio.aspx.cs" Inherits="Default2" %>

<!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 id="Head1" runat="server"><script runat="server"> void srvr_chng(object source, EventArgs e) { if (Radio1.Checked == true) span1.InnerHtml = Radio1.Value + "is selected"; else if (Radio2.Checked == true) span1.InnerHtml = Radio2.Value + "is selected"; else if (Radio3.Checked == true) span1.InnerHtml = Radio3.Value + "is selected"; } </script> <title></title></head><body> <form id="form1" runat="server"> <input id="Radio1" type="radio" value="C#" runat="server" OnServerChange="srvr_chng" align="middle" />C#<br/> <input id="Radio2" type="radio" value="VB" runat="server" onserverchange="srvr_chng" />VB<br/> <input id="Radio3" type="radio" value="PERL" runat="server" OnServerChange="srvr_chng" />PERL<br/> <p /> <span id="span1" runat="server" /> <p />

Page 35: C# Practical Final

<input id="Submit1" type="submit" value="Enter " runat="server" onserverclick="srvr_chng" /> </form></body></html>

Output:

SERVER Control Table<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Table.aspx.cs" Inherits="Default4" %>

<!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"><script runat="server">

Page 36: C# Practical Final

void page_load(object sender, EventArgs e) { int row = 0;

int numr = Convert.ToInt32(selrow.Value); int numc = Convert.ToInt32(selcol.Value); for (int j = 0; j < numr; j++) { HtmlTableRow r = new HtmlTableRow();

//set bgcolor on alternating rows if (row % 2 == 1) r.BgColor = "sky blue"; row++; for (int i = 0; i < numc; i++) { HtmlTableCell c = new HtmlTableCell(); c.Controls.Add(new LiteralControl("row" + j.ToString() + ",col" + i.ToString())); r.Cells.Add(c); } Table1.Rows.Add(r); } } </script> <title></title></head><body> <form id="form1" runat="server"> <table id="Table1" cellpadding="3" cellspacing="0" border="1" runat="server"/> Table Rows: <select id="selrow" runat="server"> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> </select>

Page 37: C# Practical Final

<br /> TAble Columns: <select id="selcol" runat="server"> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> </select> <input id="Submit1" type="submit" value="Generate Table" runat="server" /> </form></body></html>

Output:

Page 38: C# Practical Final

6)Database Programs with ASP.NET and ADO.NET

Connection.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Connection.aspx.cs" Inherits="Connection" %>

<!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> <style type="text/css"> .style1 { text-align: center; } .style2 { font-family: "Times New Roman", Times, serif; font-size: xx-large; color: #FF6600; } </style></head><body> <form id="form1" runat="server"> <div>

Page 39: C# Practical Final

<div class="style1"> <span class="style2"><strong>Admission Form</strong></span><br /> </div> <table style="width:100%;"> <tr> <td colspan="2"> Form No.:</td> <td colspan="2"> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> </td> </tr> <tr> <td colspan="2"> Name:</td> <td colspan="2"> <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox> </td> </tr> <tr> <td colspan="2"> Sex:</td> <td colspan="2"> <asp:DropDownList ID="DropDownList1" runat="server"> <asp:ListItem>Male</asp:ListItem> <asp:ListItem>Female</asp:ListItem> </asp:DropDownList> </td> </tr> <tr> <td colspan="2"> Date Of Birth: </td> <td colspan="2"> <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox> </td> </tr> <tr> <td colspan="2"> Class:</td>

Page 40: C# Practical Final

<td colspan="2"> <asp:TextBox ID="TextBox4" runat="server"></asp:TextBox> </td> </tr> <tr> <td class="style1"> <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="New" /> </td> <td class="style1"> <asp:Button ID="Button2" runat="server" onclick="Button2_Click" Text="Insert" /> </td> <td class="style1"> <asp:Button ID="Button3" runat="server" onclick="Button3_Click" Text="Delete" /> </td> <td style="text-align: center"> <asp:Button ID="Button4" runat="server" style="text-align: center" Text="Show" onclick="Button4_Click" /> </td> </tr> <tr> <td class="style1"> &nbsp;</td> <td class="style1"> &nbsp;</td> <td class="style1"> &nbsp;</td> <td style="text-align: center"> &nbsp;</td> </tr> </table> <br /> <br /> <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="ID" DataSourceID="AccessDataSource1"> <Columns>

Page 41: C# Practical Final

<asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True" SortExpression="ID" /> <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" /> <asp:BoundField DataField="sex" HeaderText="sex" SortExpression="sex" /> <asp:BoundField DataField="dob" HeaderText="dob" SortExpression="dob" /> <asp:BoundField DataField="Class" HeaderText="Class" SortExpression="Class" /> </Columns> </asp:GridView> <asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="~/employee.accdb" SelectCommand="SELECT [ID], [Name], [sex], [dob], [Class] FROM [emp]"> </asp:AccessDataSource> <br /> <br /> <br /> <br /> <br /> <br /> <br /> </div> </form></body></html>

Connection.aspx.cs

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

Page 42: C# Practical Final

using System.Web.UI;using System.Web.UI.WebControls;using System.Data.OleDb;

public partial class Connection : System.Web.UI.Page{ OleDbConnection cn; OleDbCommand cmd; string s; OleDbDataReader dr; protected void Page_Load(object sender, EventArgs e) { cn=new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C://Users/PUJARI/Documents/Visual Studio 2010/WebSites/WebSite3/employee.accdb"); }protected void Button1_Click(object sender, EventArgs e){ TextBox1.Text=""; TextBox2.Text=""; TextBox3.Text=""; TextBox4.Text = "";}protected void Button2_Click(object sender, EventArgs e){ int i; cn.Open(); s = "insert into emp values(" + Convert.ToInt32(TextBox1.Text) + ",'" + TextBox2.Text + "','" + DropDownList1.SelectedIndex + "','" + TextBox3.Text + "','" + TextBox4.Text + "')"; cmd=new OleDbCommand(s,cn); cmd.ExecuteNonQuery(); Response.Write("Record Inserted"); cn.Close();}protected void Button3_Click(object sender, EventArgs e){ try {

Page 43: C# Practical Final

cn.Open(); s = "Delete from emp where ID=" + TextBox1.Text; cmd = new OleDbCommand(s, cn); cmd.ExecuteNonQuery(); Response.Write("recored Deleted");

cn.Close();

} catch { }}protected void Button4_Click(object sender, EventArgs e){ cn.Open(); OleDbDataReader dr;

s = "select * from emp"; cmd = new OleDbCommand(s, cn); dr = cmd.ExecuteReader(); while (dr.Read()) {

}

}}

Output:

Page 44: C# Practical Final
Page 45: C# Practical Final

7)Master Page Example with Menu

<%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="MasterPage" %>

<!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> <asp:ContentPlaceHolder id="head" runat="server"> </asp:ContentPlaceHolder> <style type="text/css"> .style1 { text-align: center; } #form1 { width: 1078px; text-align: right; } </style></head><body> <p class="style1" style="font-family: 'Times New Roman', Times, serif; font-size: xx-large; color: #FFFFFF; background-color: #FFFFFF; background-image: url('/Web/headerbig3.jpg');"> <br style="background-color: #FFFFFF" /> <br style="background-image: url('/Web/headerbig3.jpg')" /> ICS College, Khed.<br /><br /> Dept. of IT/CS/BMS<br />

</p> <form id="form1" runat="server"> <asp:Menu ID="Menu1" runat="server" BackColor="#990033"

Page 46: C# Practical Final

DynamicHorizontalOffset="2" Font-Names="Times New Roman" Font-Size="Large" ForeColor="#7C6F57" Orientation="Horizontal" StaticSubMenuIndent="10px" Width="504px"> <DynamicHoverStyle BackColor="#7C6F57" ForeColor="White" /> <DynamicMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" /> <DynamicMenuStyle BackColor="#F7F6F3" /> <DynamicSelectedStyle BackColor="#5D7B9D" /> <DynamicItemTemplate><%# Eval("Text") %> </DynamicItemTemplate> <Items> <asp:MenuItem NavigateUrl="~/Institute.aspx" Text="Institute" Value="Institute"> </asp:MenuItem> <asp:MenuItem NavigateUrl="~/Acaemics.aspx" Text="Academics" Value="Academics"> </asp:MenuItem> <asp:MenuItem Text="Staff" Value="Staff"></asp:MenuItem> </Items> <StaticHoverStyle BackColor="#7C6F57" ForeColor="White" /> <StaticMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" /> <StaticSelectedStyle BackColor="#5D7B9D" /> </asp:Menu> <asp:TreeView ID="TreeView1" runat="server"> <Nodes> <asp:TreeNode NavigateUrl="~/About_ICS.aspx" Text="About ICS" Value="About ICS"> </asp:TreeNode> <asp:TreeNode Text="Vision &amp; Mission" Value="Vision &amp; Mission"> </asp:TreeNode> <asp:TreeNode Text="Our Inspiration" Value="Our Inspiration"></asp:TreeNode> <asp:TreeNode Text="Directors Message" Value="Directors Message"></asp:TreeNode> </Nodes> </asp:TreeView>

Page 47: C# Practical Final

<div> <asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server"> <p style="margin-left: 100px"> <br /> </p> </asp:ContentPlaceHolder> </div> </form></body></html>

Output:

Page 48: C# Practical Final

8)Validation Control

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="validation.aspx.cs" Inherits="validation" %>

<!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> <style type="text/css"> .style1 { text-align: center; font-size: xx-large; } </style></head><body> <form id="form1" runat="server"> <div> <table style="width:100%;"> <tr> <td class="style1" colspan="2"> <strong>Validation Control</strong></td> </tr> <tr> <td> Name:</td> <td> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="RequiredFieldValidator" ControlToValidate="TextBox1"></asp:RequiredFieldValidator> </td>

Page 49: C# Practical Final

</tr> <tr> <td> Contact No.:</td> <td> <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox> <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="TextBox2" ErrorMessage="Plz Enter Valid No."></asp:RequiredFieldValidator> </td> </tr> <tr> <td> Address:</td> <td> <asp:TextBox ID="TextBox3" runat="server" Rows="5"></asp:TextBox> </td> </tr> <tr> <td> Date of Join:</td> <td> <asp:TextBox ID="TextBox4" runat="server"></asp:TextBox> <asp:RangeValidator ID="RangeValidator2" runat="server" ControlToValidate="TextBox4" ErrorMessage="Plz Enter Valid Date" MaximumValue="05/31/2011" MinimumValue="03/01/2011">Enter date of March, April or May 2011</asp:RangeValidator> </td> </tr> <tr> <td> Email ID:</td> <td> <asp:TextBox ID="TextBox5" runat="server" Width="220px"></asp:TextBox>

Page 50: C# Practical Final

<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="TextBox5" ErrorMessage="Valid Email Address" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator> </td> </tr> <tr> <td> &nbsp;</td> <td> &nbsp;</td> </tr> </table> <asp:ValidationSummary ID="ValidationSummary1" runat="server" ShowMessageBox="True" /> <br /> <asp:Button ID="Button1" runat="server" Text="Submit" /> <br /> </div> </form></body></html>

Output:

Page 51: C# Practical Final

9) Implement the exercise on Ajax

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Ajax.aspx.cs" Inherits="Ajax" %>

<!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> <script> function loadXMLDoc() { var xmlhttp; if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp = new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange = function () {

Page 52: C# Practical Final

if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { document.getElementById("myDiv").innerHTML = xmlhttp.responseText; } } xmlhttp.open("GET", "ajax_info.txt", true); xmlhttp.send(); }</script></head><body> <form id="form1" runat="server"> <div id="myDiv"><h2>Let AJAX change this text</h2></div><button type="button" onclick="loadXMLDoc()">Change Content</button> </form></body></html>

Output:

Page 53: C# Practical Final

10)Implement the exercise in Jquery

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="jquery.aspx.cs" Inherits="Default2" %>

<!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> <script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.11.1.min.js"></script> <script type="text/javascript"> $(document).ready(function () { $(":button").click(function () {

Page 54: C# Practical Final

$("table").hide(); }); }); </script></head><body> <form id="form1" runat="server"> <div> <table border="1"> <tr><td>1</td><td>2</td><td>3</td><td>4</td></tr> <tr><td>5</td><td>6</td><td>7</td><td>8</td></tr> <tr><td>9</td><td>10</td><td>11</td><td>12</td></tr> </table> <br /> <input type="button" value="Hide the Table" />

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

Output:

Page 55: C# Practical Final