ghost

ML

1. 

import cv2

from matplotlib import pyplot as plt

crick1 = cv2.imread('OIP.jpg',1)

plt.imshow(crick1[:,:,::-1])

import cv2

from matplotlib import pyplot as plt

crick1 = cv2.imread('OIP.jpg',1)

plt.imshow(crick1[:,:,::-1])

gray_img = cv2.cvtColor (crick1, cv2.COLOR_BGR2GRAY) 

plt.imshow(gray_img,cmap='gray')

import cv2

crick1 = cv2.imread('OIP.jpg',1)

gray_img = cv2.cvtColor (crick1, cv2.COLOR_BGR2GRAY)

haar_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')

mouth_cascade = cv2.CascadeClassifier('haarcascade_mcs_mouth.xml')

faces = haar_cascade.detectMultiScale(gray_img,1.3,5)

for (x, y, w, h) in faces:

    cv2.rectangle(crick1, (x, y), (x+w, y+h), (255, 0, 0), 2)

    roi_gray = gray_img[y:y+h, x:x+w]

    roi_color = crick1[y:y+h, x:x+w]


    mouth = mouth_cascade.detectMultiScale(roi_gray)


    for (ex,ey,ew,eh) in mouth:

        cv2.rectangle(roi_color,(ex,ey),(ex+ew,ey+eh),(255,0,0),2)


cv2.imshow('Detected faces', crick1)


cv2.waitKey(0)

cv2.destroyAllWindows()

2.

 import cv2

from matplotlib import pyplot as plt

crick1 = cv2.imread('OIP.jpg',1)

plt.imshow(crick1[:,:,::-1])

import cv2

from matplotlib import pyplot as plt

crick1 = cv2.imread('OIP.jpg',1)

plt.imshow(crick1[:,:,::-1])

gray_img = cv2.cvtColor (crick1, cv2.COLOR_BGR2GRAY) 

plt.imshow(gray_img,cmap='gray')

import cv2

crick1 = cv2.imread('OIP.jpg',1)

gray_img = cv2.cvtColor (crick1, cv2.COLOR_BGR2GRAY)

haar_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')

eye_cascade = cv2.CascadeClassifier('haarcascade_eye.xml.')

faces = haar_cascade.detectMultiScale(gray_img,1.3,5)

for (x, y, w, h) in faces:

    cv2.rectangle(crick1, (x, y), (x+w, y+h), (255, 0, 0), 2)

    roi_gray = gray_img[y:y+h, x:x+w]

    roi_color = crick1[y:y+h, x:x+w]


    eyes = eye_cascade.detectMultiScale(roi_gray)


    for (ex,ey,ew,eh) in eyes:

        cv2.rectangle(roi_color,(ex,ey),(ex+ew,ey+eh),(255,0,0),2)


    eye_roi_gray = roi_gray[ey:ey+eh, ex:ex+ew]

    eye_roi_color = roi_color[ey:ey+eh, ex:ex+ew]


    _, eye_thresh = cv2.threshold(eye_roi_gray, 50, 255, cv2.THRESH_BINARY_INV)

    contours, _ = cv2.findContours(eye_thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)


    if len(contours) > 0:

        pupil = max(contours, key=cv2.contourArea)

        x1, y1, w1, h1 = cv2.boundingRect(pupil)

        center = (int(x1 + w1/2), int(y1 + h1/2))

        cv2.circle(eye_roi_color, center, 3, (0, 0, 255), -1)


cv2.imshow('Detected faces', crick1)


cv2.waitKey(0)

cv2.destroyAllWindows()

3 .Face, Eye and PUPIL Detection 

import cv2 from matplotlib import pyplot as plt crick1 = cv2.imread('albert.jpg',1) |plt.imshow(crick1[:,:,::-1]) gray_img = cv2.cvtColor (crick1, cv2.COLOR_BGR2GRAY) plt.imshow(gray_img,cmap='gray') import cv2 crick1 cv2.imread('albert.jpg',1) gray_img = cv2.cvtColor (crick1, cv2.COLOR_BGR2GRAY) haar_cascade = cv2.Cascadeclassifier('haarcascade_frontalface_default.xml') eye_cascade = cv2.Cascadeclassifier('haarcascade_eye.xml.') haar_cascade.detectMultiScale(gray_img,1.3,5) faces for (x, y, w, h) in faces: cv2.rectangle(crick1, (x, y), (xw, y+h), (255, 0, 0), 2) roi_gray = gray_img[y:y+h, x:x*w] roi_color = crick1[y:y h, x:x w] eyes = eye_cascade.detectMultiScale(roi_gray) for (ex, ey, ew, eh) in eyes: cv2.rectangle(roi_color, (ex,ey), (ex+ew,ey+eh), (255,0,0),2) eye_roi_gray = roi_gray[ey:ey eh, ex:ex ew] eye_roi_color = roi_color[ey:ey+eh, ex:ex ew] eye_thresh = cv2.threshold(eye_roi_gray, 50, 255, cv2.THRESH_BINARY_INV) contours, cv2.findContours(eye_thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE) if len(contours) > 0: pupil = max(contours, key=cv2.contourArea) x1, y1, w1, h1 = cv2.boundingRect(pupil) center = (int(x1 + w1/2), int(y1 + h1/2)) cv2.circle(eye_roi_color, center, 3, (0, 0, 255), -1) cv2.imshow('Detected faces', crick1) cv2.waitKey(0) cv2.destroyAllwindows

android

Program-10 Write a program for database CRUD operations using sqlite. Databasehelper.kt
import android.content.ContentValues import android.content.Context import android
.database.Cursor
import android.database.sqlite.SQLiteDatabase import android.database.sqlite.SQLiteOpenHelper
  
class DBHelper(context: Context) : SQLiteOpenHelper(context, DATABASE_NAME, null, DATABASE_VERSION) {
companion object {
const val DATABASE_NAME = "mydatabase.db" const val DATABASE_VERSION = 1
const val TABLE_NAME = "users"
const val COLUMN_ID = "id"
const val COLUMN_NAME = "name"
const val COLUMN_CITY = "city"
}
override fun onCreate(db: SQLiteDatabase?) { val createTableSQL = """
CREATE TABLE $TABLE_NAME (
$COLUMN_ID INTEGER PRIMARY KEY AUTOINCREMENT, $COLUMN_NAME TEXT,
$COLUMN_CITY TEXT
)
""".trimIndent() db?.execSQL(createTableSQL)
}
override fun onUpgrade(db: SQLiteDatabase?, oldVersion: Int, newVersion: Int) { db?.execSQL("DROP TABLE IF EXISTS $TABLE_NAME")
onCreate(db)
}
// Insert record
fun insertRecord(name: String, city: String): Long {
val db = writableDatabase
val values = ContentValues().apply {
put(COLUMN_NAME, name)
put(COLUMN_CITY, city) }
return db.insert(TABLE_NAME, null, values) }
// Update record
fun updateRecord(id: Int, name: String, city: String): Int {
val db = writableDatabase
val values = ContentValues().apply {
put(COLUMN_NAME, name)
put(COLUMN_CITY, city) }
return db.update(TABLE_NAME, values, "$COLUMN_ID = ?", arrayOf(id.toString())) }
// Select all records
fun getAllRecords(): Cursor {

val db = readableDatabase
return db.rawQuery("SELECT * FROM $TABLE_NAME", null) }
// Delete record by ID
fun deleteRecord(id: Int): Int {
val db = writableDatabase
return db.delete(TABLE_NAME, "$COLUMN_ID = ?", arrayOf(id.toString())) }
}
MainActivity.kt
package com.example.demosqlitesem6
import DBHelper
import android.annotation.SuppressLint
import android.database.Cursor
import android.os.Bundle
import android.widget.Button
import android.widget.EditText
import android.widget.Toast
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
class MainActivity : AppCompatActivity() {
private lateinit var dbHelper: DBHelper private lateinit var nameEditText: EditText private lateinit var cityEditText: EditText private lateinit var idEditText: EditText private lateinit var insertButton: Button private lateinit var updateButton: Button private lateinit var deleteButton: Button private lateinit var selectButton: Button
@SuppressLint("Range")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) setContentView(R.layout.activity_main)
dbHelper = DBHelper(this)
nameEditText = findViewById(R.id.nameEditText) cityEditText = findViewById(R.id.cityEditText) idEditText = findViewById(R.id.idEditText) insertButton = findViewById(R.id.insertButton) updateButton = findViewById(R.id.updateButton)
 
deleteButton = findViewById(R.id.deleteButton) selectButton = findViewById(R.id.selectButton)
// Insert record insertButton.setOnClickListener {
val name = nameEditText.text.toString() val city = cityEditText.text.toString()
if (name.isNotEmpty() && city.isNotEmpty()) { val result = dbHelper.insertRecord(name, city) if (result != -1L) {
Toast.makeText(this, "Record inserted", Toast.LENGTH_SHORT).show() }else{
Toast.makeText(this, "Failed to insert record", Toast.LENGTH_SHORT).show() }
} else {
Toast.makeText(this, "Please fill all fields", Toast.LENGTH_SHORT).show()
} }
// Update record updateButton.setOnClickListener {
val id = idEditText.text.toString().toIntOrNull() val name = nameEditText.text.toString()
val city = cityEditText.text.toString()
if (id != null && name.isNotEmpty() && city.isNotEmpty()) { val result = dbHelper.updateRecord(id, name, city)
if (result > 0) {
Toast.makeText(this, "Record updated", Toast.LENGTH_SHORT).show() }else{
Toast.makeText(this, "Failed to update record", Toast.LENGTH_SHORT).show() }
} else {
Toast.makeText(this, "Please fill all fields", Toast.LENGTH_SHORT).show()
} }
// Delete record deleteButton.setOnClickListener {
val id = idEditText.text.toString().toIntOrNull() if (id != null) {
val result = dbHelper.deleteRecord(id) if (result > 0) {
Toast.makeText(this, "Record deleted", Toast.LENGTH_SHORT).show() }else{
Toast.makeText(this, "Failed to delete record", Toast.LENGTH_SHORT).show() }
} else {
Toast.makeText(this, "Please enter a valid ID", Toast.LENGTH_SHORT).show()

} }
// Select all records selectButton.setOnClickListener {
val cursor: Cursor = dbHelper.getAllRecords() if (cursor.moveToFirst()) {
val result = StringBuilder() do{
val id = cursor.getInt(cursor.getColumnIndex(DBHelper.COLUMN_ID))
val name = cursor.getString(cursor.getColumnIndex(DBHelper.COLUMN_NAME)) val city = cursor.getString(cursor.getColumnIndex(DBHelper.COLUMN_CITY)) result.append("ID: $id, Name: $name, City: $city\n")
} while (cursor.moveToNext())
Toast.makeText(this, result.toString(), Toast.LENGTH_LONG).show() } else {
Toast.makeText(this, "No records found", Toast.LENGTH_SHORT).show() }
} }
} Activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/main" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"
android:padding="20dp" tools:context=".MainActivity">
<EditText android:id="@+id/nameEditText" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="Enter Name" android:minHeight="48dp" />
<EditText
android:id="@+id/cityEditText" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="Enter City" android:minHeight="48dp" />
<EditText android:id="@+id/idEditText"
 
android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="Enter ID (for update/delete)" android:inputType="number" android:minHeight="48dp" />
<Button
android:id="@+id/insertButton" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Insert" />
<Button android:id="@+id/updateButton" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Update" />
<Button android:id="@+id/deleteButton" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Delete" />
<Button
android:id="@+id/selectButton" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Select All" />
</LinearLayout>

asp.net
crud
step 1 - create database
step 2 -  (create table)
 CREATE TABLE mytbl (
    ID INT PRIMARY KEY IDENTITY,
    StudentName NVARCHAR(50),
    Address NVARCHAR(100),
Country NVARCHAR(30),
State NVARCHAR(20),
City NVARCHAR(20)
);


step 3 - web.config (xml file)

<?xml version="1.0" encoding="utf-8"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
  <connectionStrings>
    <add name="mystr" connectionString="data source=DESKTOP-49G35VP;initial catalog=Mydb;integrated security=SSPI" />
    <add name="MydbConnectionString" connectionString="Data Source=DESKTOP-49G35VP;Initial Catalog=Mydb;Integrated Security=True"
      providerName="System.Data.SqlClient" />
  </connectionStrings>
  <system.web>
    
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />
  </system.web>
</configuration>


 step 4 webform.aspx

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

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
<asp:Label ID="lblMessage" runat="server" ForeColor="Red" Font-Bold="True" />
        <div>
            <table>
                <tr>
                    <td>ID</td>
                    <td><asp:TextBox ID="txtid" runat="server"></asp:TextBox></td>
                    <td>
                        <asp:Button ID="btndlt" runat="server" Text="Delete" OnClick="btndlt_Click" />
                        <asp:Button ID="btnsrch" runat="server" Text="Find" OnClick="btnsrch_Click" />

                    </td>
                </tr>
                <tr>
                    <td>StudentName</td>
                    <td>
                        <asp:TextBox ID="txtname" runat="server"></asp:TextBox></td>
                </tr>
                <tr>
                    <td>Address</td>
                    <td>
                        <asp:TextBox ID="txtadd" runat="server"></asp:TextBox></td>
                </tr>
                <tr>
                    <td>Country</td>
                    <td>
                        <asp:TextBox ID="txtcountry" runat="server"></asp:TextBox></td>
                </tr>
                <tr>
                    <td>State</td>
                    <td>
                        <asp:TextBox ID="txtstate" runat="server"></asp:TextBox></td>
                </tr>
                <tr>
                    <td>City</td>
                    <td>
                        <asp:TextBox ID="txtcity" runat="server"></asp:TextBox></td>
                </tr>
                <tr>
                    <td colspan="2">
                        <asp:Button ID="btnadd" runat="server" Text="Insert" OnClick="btnadd_Click" />
                        <asp:Button ID="btnupdate" runat="server" Text="Update" OnClick="btnupdate_Click" />
                        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="id" DataSourceID="SqlDataSource1" AutoGenerateDeleteButton="True" AutoGenerateEditButton="True">
                            <Columns>
                                <asp:BoundField DataField="id" HeaderText="id" InsertVisible="False" ReadOnly="True" SortExpression="id" />
                                <asp:BoundField DataField="studentname" HeaderText="studentname" SortExpression="studentname" />
                                <asp:BoundField DataField="address" HeaderText="address" SortExpression="address" />
                                <asp:BoundField DataField="country" HeaderText="country" SortExpression="country" />
                                <asp:BoundField DataField="state" HeaderText="state" SortExpression="state" />
                                <asp:BoundField DataField="city" HeaderText="city" SortExpression="city" />
                            </Columns>
                        </asp:GridView>
                        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:MydbConnectionString %>" SelectCommand="SELECT * FROM [mytbl]" UpdateCommand="" DeleteCommand=""></asp:SqlDataSource>
                    </td>
                </tr>
            </table>
        </div>
    </form>
</body>
</html>

step 5 webform.aspx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

namespace WebApplication1
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        string constr = ConfigurationManager.ConnectionStrings["mystr"].ConnectionString;
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnadd_Click(object sender, EventArgs e)
        {
            InsertData();
        }

        private void InsertData()
        {
            try
            {
                SqlConnection cn = new SqlConnection(constr);
                cn.Open();
                SqlCommand cmd = new SqlCommand("insert into mytbl(studentname,address,country,state,city)values(@snm,@add,@country,@state,@city)", cn);
                cmd.Parameters.AddWithValue("@snm", txtname.Text);
                cmd.Parameters.AddWithValue("@add", txtadd.Text);
                cmd.Parameters.AddWithValue("@country", txtcountry.Text);
                cmd.Parameters.AddWithValue("@state", txtstate.Text);
                cmd.Parameters.AddWithValue("@city", txtcity.Text);
                cmd.ExecuteNonQuery();
                cn.Close();



            }
            catch (Exception ex)
            {
                
                throw ex;
            }
    lblMessage.Text = "Record inserted successfully!";
        }

        protected void btndlt_Click(object sender, EventArgs e)
        {
            DeleteData();
        }

        private void DeleteData()
        {
            try
            {
                SqlConnection cn = new SqlConnection(constr);
                cn.Open();
                SqlCommand cmd = new SqlCommand("delete from mytbl where id=@id", cn);

                cmd.Parameters.AddWithValue("@id", txtid.Text);
                cmd.ExecuteNonQuery();

            }
            catch (Exception ex)
            {
                
                throw ex;
            }
    lblMessage.Text = "Record deleted successfully!";
        }

        protected void btnsrch_Click(object sender, EventArgs e)
        {
            FindData();
        }

        private void FindData()
        {
            try
            {
                SqlConnection cn = new SqlConnection(constr);
                cn.Open();
                SqlCommand cmd = new SqlCommand("select * from mytbl where id=@id", cn);
                cmd.Parameters.AddWithValue("@id", txtid.Text);
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                DataTable dt = new DataTable();
                da.Fill(dt);
                if (dt.Rows.Count >0)
                {
                    txtname.Text = dt.Rows[0]["studentname"].ToString();
                    txtadd.Text = dt.Rows[0]["address"].ToString();
                    txtcountry.Text = dt.Rows[0]["country"].ToString();
                    txtstate.Text = dt.Rows[0]["state"].ToString();
                    txtcity.Text = dt.Rows[0]["city"].ToString();
                }
                cn.Close();
            }
            catch (Exception ex)
            {
                
                throw ex;
            }
    lblMessage.Text = "Record find successfully!";
        }

        protected void btnupdate_Click(object sender, EventArgs e)
        {
            Updatedata();
        }

        private void Updatedata()
        {
            try
            {
                SqlConnection cn = new SqlConnection(constr);
                cn.Open();
                SqlCommand cmd = new SqlCommand("update mytbl set studentname=@snm,address=@add,country=@country,state=@state,city=@city where id=@id", cn);
                cmd.Parameters.AddWithValue("@snm", txtname.Text);
                cmd.Parameters.AddWithValue("@add", txtadd.Text);
                cmd.Parameters.AddWithValue("@country", txtcountry.Text);
                cmd.Parameters.AddWithValue("@state", txtstate.Text);
                cmd.Parameters.AddWithValue("@city", txtcity.Text);
                cmd.Parameters.AddWithValue("@id", txtid.Text);
                cmd.ExecuteNonQuery();
                cn.Close();


            }
            catch (Exception ex)
            {
                
                throw ex;
            }
    lblMessage.Text = "Record updated successfully!";
        }
    }
}



JOURNAL INDEX
1. READING AND WRITING DATASET WITH XML (PROGRAM 1)
2. READING AND WRITING DATASET WITH XML (PROGRAM 1)
3. WRITE A PROGRAM TO DISPLAY DATA OF XML THROUGH
XML CONTROL
4. WEBSERVICE PROGRAM

1. Reading AND Writing DataSet With XML (program 1)
XMlDemo.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="XMlDemo.aspx.cs"
Inherits="XMlDemo" %>
<!DOCTYPE html PUBLIC "-
//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xh
tml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table>
<tr>
<td style="width: 100px">
Name:</td>
<td style="width: 100px">
<asp:TextBox ID="txtName1" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td style="width: 100px">
Address:</td>
<td style="width: 100px">
<asp:TextBox ID="txtLocation1" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td style="width: 100px">
Email:</td>
<td style="width: 100px">
<asp:TextBox ID="txtEmail1" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td style="width: 100px" valign="top">
Phone:</td>

<td style="width: 100px">
<asp:TextBox ID="txtPhone1" runat="server" TextMode="MultiLin
e" Height="104px"></asp:TextBox>
</td>
</tr>
<tr>
<td></td>
<td>
<asp:Button ID="btnSubmit" runat="server" OnClick="btnSubmit_
Click" Text="Submit" />
</td>
</tr>
</table>
<br />
<asp:DataList ID="dlComments" Runat="server" Width="100%">
<ItemTemplate>
<hr size=0/> Name:

<%# DataBinder.Eval(Container.DataItem, "name") %><br /> E-
mail:

<a href="mailto:<%# DataBinder.Eval(Container.DataItem, " email
") %>">
<%# DataBinder.Eval(Container.DataItem, "email") %>
</a><br /> Location:
<%# DataBinder.Eval(Container.DataItem, "Address") %><br /> E
mail:
<%# DataBinder.Eval(Container.DataItem, "EMail") %><br /> P
hone:
<%# DataBinder.Eval(Container.DataItem, "Phone") %>
</ItemTemplate>
</asp:DataList>
</div>
</form>
</body>
</html>
XMlDemo.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Xml;
using System.IO;
public partial class XMlDemo: System.Web.UI.Page
{

public static string constr = ConfigurationManager.ConnectionStrings["ConString"]
.ConnectionString;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Directory.Exists(HttpContext.Current.Server.MapPath("~/Upload")))
BindDatalist();
}
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
try
{
if (txtName1.Text != "" && txtEmail1.Text != "" && txtPhone1.Text != "" &
& txtLocation1.Text != "")
{
if (!Directory.Exists(HttpContext.Current.Server.MapPath("~/Upload"))) // i
f not created then it will create it.
{
Directory.CreateDirectory(HttpContext.Current.Server.MapPath("~/Uplo
ad"));
XmlDocument xmlDoc = new XmlDocument();
XmlNode rootNode = xmlDoc.CreateElement("Contact");
XmlNode subNode = xmlDoc.CreateElement("Detail");
xmlDoc.AppendChild(rootNode);
rootNode.AppendChild(subNode);
XmlNode userNode = xmlDoc.CreateElement("Name");
userNode.InnerText = txtName1.Text;
subNode.AppendChild(userNode);
XmlNode userEmail = xmlDoc.CreateElement("Email");
userEmail.InnerText = txtEmail1.Text;
subNode.AppendChild(userEmail);
XmlNode userPhone = xmlDoc.CreateElement("Phone");
userPhone.InnerText = txtPhone1.Text;
subNode.AppendChild(userPhone);
XmlNode userAddress = xmlDoc.CreateElement("Address");
userAddress.InnerText = txtLocation1.Text;
subNode.AppendChild(userAddress);
xmlDoc.Save(HttpContext.Current.Server.MapPath("~/Upload") + "/" + "
ContactPerson.xml");
BindDatalist();
}
else
{
string FileName = HttpContext.Current.Server.MapPath("~/Upload") + "/
" + "ContactPerson.xml";
//IDVal=XDocument.Load(HttpContext.Current.Server.MapPath("~/Con
tactFile") + "/" + "ContactPerson.xml");

// int Id = (int)(from b in Contact.Descendants ("Detail") orderby (int)b.El
ement("ID") descending select (int)b.Element("ID")).FirstOrDefault() + 1;
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(FileName);
XmlNode Root = xmlDoc.DocumentElement;
System.Xml.XmlNode myXmlNode = xmlDoc.DocumentElement.FirstC
hild;
XmlElement page = xmlDoc.CreateElement("Detail");
XmlElement Name = xmlDoc.CreateElement("Name");
XmlElement Email = xmlDoc.CreateElement("Email");
XmlElement Phone = xmlDoc.CreateElement("Phone");
XmlElement Address = xmlDoc.CreateElement("Address");
XmlText textName = xmlDoc.CreateTextNode(txtName1.Text);
XmlText txtEmail = xmlDoc.CreateTextNode(txtEmail1.Text);
XmlText txtPhone = xmlDoc.CreateTextNode(txtPhone1.Text);
XmlText txtAddress = xmlDoc.CreateTextNode(txtLocation1.Text);
page.AppendChild(Name);
page.AppendChild(Email);
page.AppendChild(Phone);
page.AppendChild(Address);
Name.AppendChild(textName);
Email.AppendChild(txtEmail);
Phone.AppendChild(txtPhone);
Address.AppendChild(txtAddress);
xmlDoc.DocumentElement.InsertBefore(page, myXmlNode);
xmlDoc.Save(FileName);
BindDatalist();
}
}
}
catch (Exception ex)
{}
finally
{
txtLocation1.Text = "";
txtPhone1.Text = "";
txtEmail1.Text = "";
txtName1.Text = "";
}
}
private void BindDatalist()
{
XmlTextReader xmlreader = new XmlTextReader(HttpContext.Current.Server.
MapPath("~/Upload") + "/" + "ContactPerson.xml");
DataSet ds = new DataSet();
ds.ReadXml(xmlreader);
xmlreader.Close();
if (ds.Tables.Count != 0)
{
dlComments.DataSource = ds;

dlComments.DataBind();
}
else
{
dlComments.DataSource = null;
dlComments.DataBind();
}
}
}

2. Reading AND Writing DataSet With XML (program 1)
Employee.xml
<?xml version="1.0" encoding="utf-8"?>
<EmployeeInformation>
</EmployeeInformation>
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">
<title></title>
<style type="text/css">
.style1 {
width: 40%;
border-style: solid;
border-width: 1px;
background-color: Silver;
height: 152px;
}
.style2 {
width: 295px;
}

.style3 {
width: 754px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<table class="style1">
<tr>
<td class="style2">&nbsp;</td>
<td
class="style3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Employee_Information</td>
</tr>
<tr>
<td class="style2">Name:</td>
<td class="style3">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style2">Emp_Id:</td>
<td class="style3">
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style2">Qualification:</td>
<td class="style3">
<asp:DropDownList ID="DropDownList1" runat="server"
Height="22px" Width="132px">
<asp:ListItem>--SELECT--</asp:ListItem>
<asp:ListItem>MCA</asp:ListItem>
<asp:ListItem>BCA</asp:ListItem>
<asp:ListItem>MBA</asp:ListItem>
<asp:ListItem>BBA</asp:ListItem>
<asp:ListItem>BTech</asp:ListItem>
<asp:ListItem>MTech</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td class="style2">&nbsp;</td>
<td class="style3">
<asp:Button ID="Button1" runat="server" Text="Submit"
OnClick="Button1_Click" />
<asp:Button ID="Button2" runat="server" OnClick="Button2_Click"
Text="Show" />

</td>
</tr>
</table>
<asp:DataList ID="DataList1" runat="server" BackColor="#DEBA84"
BorderColor="#DEBA84"
BorderStyle="None" BorderWidth="1px" CellPadding="3"
CellSpacing="2" GridLines="Both" RepeatDirection="Horizontal"
Style="margin-right: 32px">
<FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" />
<HeaderStyle BackColor="#A55129" Font-Bold="True"
ForeColor="White" />
<ItemStyle BackColor="#FFF7E7" ForeColor="#8C4510" />
<SelectedItemStyle BackColor="#738A9C" Font-Bold="True"
ForeColor="White" />
<ItemTemplate>
<hr size="0" />
Name:<%#DataBinder.Eval(Container.DataItem,"name")%><br />
Emp_id:<%#DataBinder.Eval(Container.DataItem,"Emp_id")%></a><br
/>
Qualification:<%#DataBinder.Eval(Container.DataItem,"Qualification")%><br />
</ItemTemplate>
</asp:DataList>
<br />
</div>
</form>
</body>
</html>
Default.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Xml;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindDatalist();
}
}
private void BindDatalist()
{

XmlTextReader xmlreader = new
XmlTextReader(Server.MapPath("Employee.xml"));
DataSet ds = new DataSet();
ds.ReadXml(xmlreader);
xmlreader.Close();
if (ds.Tables.Count != 0)
{
DataList1.DataSource = ds;
DataList1.DataBind();
}
else
{
DataList1.DataSource = null;
DataList1.DataBind();
}
}
protected void Button1_Click(object sender, EventArgs e){
XmlDocument xmldoc = new XmlDocument();
xmldoc.Load(Server.MapPath("Employee.xml"));
BindDatalist(); }
protected void Button2_Click(object sender, EventArgs e)
{
XmlDocument xmldoc = new XmlDocument();
xmldoc.Load(Server.MapPath("Employee.xml"));
XmlElement parentelement = xmldoc.CreateElement("Details");
XmlElement name = xmldoc.CreateElement("Name");
name.InnerText = TextBox1.Text;
XmlElement Emp_id = xmldoc.CreateElement("Emp_id");
Emp_id.InnerText = TextBox2.Text;
XmlElement Qualification = xmldoc.CreateElement("Qualification");
Qualification.InnerText = DropDownList1.SelectedItem.Text;
parentelement.AppendChild(name);
parentelement.AppendChild(Emp_id);
parentelement.AppendChild(Qualification);
xmldoc.DocumentElement.AppendChild(parentelement);
xmldoc.Save(Server.MapPath("Employee.xml"));
}}

3. Display XML Document in ASP.NET using XML Control
Tubestation.xml
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

<undergroundList>
<underground>
<name>ABC</name>
<lines> TEST 1</lines>
<postCode>XYZ123</postCode>
</underground>
<underground>
<name>ABC 123</name>
<lines> TEST 2</lines>
<postCode>XYZ 456</postCode>
</underground>
<underground>
<name>ABC 456</name>
<lines> TEST 3</lines>
<postCode>XYZ 789</postCode>
</underground>
</undergroundList>
Listview.xslt
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes"/>
<xsl:template match="/undergroundList">
<div style="font-family:Verdana; font-size:8pt;">
<xsl:for-each select="underground">
<span style="color:blue; font-weight:bold;font-size:10pt;">
<xsl:value-of select="name"/>
</span>
<br />
<b>Post Code: </b>
<xsl:value-of select="postCode"/>
<br />
<b>Lines: </b>
<xsl:value-of select="lines"/>
<hr />
</xsl:for-each>
</div>
</xsl:template>
</xsl:stylesheet>
TableView.xslt
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes"/>
<xsl:template match="/undergroundList">
<div style="font-family:Verdana; font-size:9pt;">
<table style="width:100%; border: solid 1px #336699;" cellspacing="0"
cellpadding="5" border="1">
<tr style="background-color:#336699; color:white; font-weight:bold;">
<td>Station Name</td>

<td>Post Code</td>
<td>Lines</td>
</tr>
<xsl:for-each select="underground">
<tr>
<td>
<xsl:value-of select="name"/>
</td>
<td>
<xsl:value-of select="postCode"/>
</td>
<td>
<xsl:value-of select="lines"/>
</td>
</tr>
</xsl:for-each>
</table>
</div>
</xsl:template>
</xsl:stylesheet>
Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs"
Inherits="Default2" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Xml ID="Xml1" runat="server" DocumentSource="~/TubeStations.xml"
TransformSource="~/ListView.xslt"></asp:Xml>
<asp:Xml ID="Xml2" runat="server" DocumentSource="~/TubeStations.xml"
TransformSource="~/TableView.xslt"></asp:Xml>
</div>
</form>
</body>
</html>

4. WEBSERVICE PROGRAM
Step 1 and 2
Service.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX,
uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class Service : System.Web.Services.WebService
{
[WebMethod]
public int Multiplication(int a,int b)
{
return (a*b);
}
}
Service.asmx-
<%@ WebService Language="C#" CodeBehind="~/App_Code/Service.cs" Class="S
ervice" %>
Step 3- Build Web Service and Run the Web Service for testing by pressing F5
function key.

Copy the URL of this web service for further use.
Click on the Multiplication button to test the web service.

Enter the value of a and b.

By pressing the "Invoke" button a XML file is generated.

Now our web service is ready to use; we just need to create a new web site to consume
the web service.
Example of Testing Web Service in .Net.
Step 5- Create a Test Web Site by File > New > Web Site > Asp.net Web Site

Name the web site, for example here I have choosen the name "Test".
Step 6- Right-click Solution Explorer and choose "Add Web Reference".
Step 7- Paste the URL of the web service and click on 'Go' button and then 'Add
reference'.

Step 8- Now your web service is ready to use in the Solution Explorer you will see.

Step 9- Go to the design of the Default.aspx page; drag and drop three Textboxes and one
button.

Step 10- Go to Default.cs page and on the button click event use the following code.
protected void Button1_Click(object sender, EventArgs e)
{
localhost.Service mys = new localhost.Service(); // you need to create the
object of the web service
int a = Convert.ToInt32(TextBox1.Text);
int b = Convert.ToInt32(TextBox2.Text);
int c = mys.Multiplication(a, b);
TextBox3.Text = c.ToString();
}

Step 11- After pressing the F5 function key to run the website, you will see:

1. EXAMPLE OF MASTER PAGE
 Files to write

o Masterpage.master
o Page1.aspx
o Page2.aspx
o Page3.aspx

a. Masterpage.master
<%@ Master Language="C#" AutoEventWireup="true"
CodeFile="MainMaster.master.cs" Inherits="MainMaster" %>
<!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 {
width: 97%;
height: 441px;
}
.style2 {
height: 25px;
}
.style3 {
height: 389px;
}
.style5 {
}
.style6 {
height: 389px;
width: 87px;
}
.style7 {
background-color: #FF5050;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<table class="style1">
<tr>
<td bgcolor="#FF66FF" class="style2" colspan="2">This is My
LOGO--------
<asp:Label ID="lblMainMaster" runat="server"
Text="MainMaster"></asp:Label>
</td>
</tr>
<tr>
<td bgcolor="#FF5050" class="style6" valign="top">
<span class="style7"><a
href="Page1.aspx">Page1.aspx</a></span><br />
<a href="Page2.aspx">Page2.aspx</a><br />
<a href="Page3.aspx">Page3.aspx</a></td>
<td bgcolor="White" class="style3" valign="top">
<asp:ContentPlaceHolder ID="cphPageContent" runat="server">
<p>
Under Construction
</p>
</asp:ContentPlaceHolder>
</td>
</tr>
<tr>
<td bgcolor="#FF33CC" class="style5" colspan="2">Copyright
ND.....(This Footer)</td>
</tr>
</table>
</div>
</form>
</body>
</html>

b. Page1.aspx
<%@ Page Title="" Language="C#" MasterPageFile="~/MainMaster.master"
AutoEventWireup="true" CodeFile="Page1.aspx.cs" Inherits="Page1" %>
<%@ MasterType VirtualPath="~/MainMaster.master" %>
<asp:Content ID="Content2" runat="server"
ContentPlaceHolderID="head">
<script language="javascript" type="text/javascript">
function ShowAlert()
{
alert(document.forms[0].<%=TextBox1.UniqueID %>.value);
}
</script>
</asp:Content>
<asp:Content ID="Content1" runat="server"
ContentPlaceHolderID="cphPageContent">
<p>
This is Page1 content<asp:TextBox
ID="TextBox1" runat="server"></asp:TextBox>
&nbsp;<input id="btnSayHello" type="button" value="SayHello"
onclick="ShowAlert()" />
</p>
<p>
About Page1:-The Story begins like this.......
</p>
</asp:Content>
<%--<asp:Content ID="Content2" runat="server"
contentplaceholderid="cphHeader">
Page1
</asp:Content>--%>
c. Page1.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 Page1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//Label lbl = (Label)Master.FindControl("lblMainMaster");
//lbl.Text = "From Page1";
Master.LabelInMaster.Text = "From Page1";
}
}

d. Page2.aspx
<%@ Page Title="" Language="C#" MasterPageFile="~/MainMaster.master"
AutoEventWireup="true" CodeFile="Page2.aspx.cs" Inherits="Page2" %>
<%@ MasterType VirtualPath="~/MainMaster.master" %>
<asp:Content ID="Content1" runat="server"
ContentPlaceHolderID="cphPageContent">
<p>
This is Page2
</p>
<p>
About Page:-ND
</p>
</asp:Content>

<%--<asp:Content ID="Content2" runat="server"
contentplaceholderid="cphHeader">
Page2
</asp:Content>--%>
e. Page2.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 Page2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//Label lbl = (Label)Master.FindControl("lblMainMaster");
//lbl.Text = "From Page2";
Master.LabelInMaster.Text = "From Page2";
}
}
f. Page3.aspx
<%@ Page Title="" Language="C#" MasterPageFile="~/MainMaster.master"
AutoEventWireup="true" CodeFile="Page3.aspx.cs" Inherits="Page3" %>
<%@ MasterType VirtualPath="~/MainMaster.master" %>
<%--<asp:Content ID="Content2" runat="server"
contentplaceholderid="cphHeader">
Page3
</asp:Content>--%>
g. Page3.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 Page3 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//Label lbl = (Label)Master.FindControl("lblMainMaster");
//lbl.Text = "From Page3";
Master.LabelInMaster.Text = "From Page3";
}
}

2. EXAMPLE OF SKINFILE
a. Skinfile.skin
<asp:Label runat="server" ForeColor="RED" SkinID="lbltxt" Text="Label">
</asp:Label>
<asp:TextBox runat="server" ForeColor="DarkBlue" SkinID="txt" >
</asp:TextBox>
<asp:Button runat="server" Text="Button" ForeColor="Chocolate"
SkinID="btn"/>
b. Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" Theme="CommonDesign"
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></title>
</head>
<body>
<form id="form1" runat="server">
<br /><br /><br />
<div>
<asp:Label ID="Label1" runat="server" SkinID="lbltxt" Text="Label">
</asp:Label>
<br />
<asp:TextBox ID="TextBox1" runat="server" SkinID="txt">
</asp:TextBox><br />
<asp:Button ID="Button1" runat="server" SkinID="btn" Text="Button" />
</div>
</form>
</body>
</html>

3. OUTPUT CACHE
 Index for journal
o Example of Output Cache with Duration
o Example of Output Cache with Control
o Example of Output Cache with Custom
o Example of Output Cache with Param
 File to write
o Default.aspx
o OutputCacheWithDuration.aspx
o OutputCacheWithDuration.aspx .cs
o OutputCacheWithControl.aspx
o OutputCacheWithControl.aspx.cs
o OutputCacheWithCustom.aspx
o OutputCacheWithCustom.aspx.cs
o OutputCacheWithParam.aspx
o OutputCacheWithParam.aspx.cs
a. 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">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
<asp:HyperLink ID="HyperLink1" runat="server"
NavigateUrl="~/OutputCacheWithDuration.aspx">OutPutCacheWithDuration</asp:
HyperLink>
<br />
<br />
<asp:HyperLink ID="HyperLink2" runat="server"
NavigateUrl="~/OutputCacheWithControl.aspx">OutPutCacheWithVaryByControl
</asp:HyperLink>
<br />
<br />
<asp:HyperLink ID="HyperLink3" runat="server"
NavigateUrl="~/OutputCacheWithCustom.aspx">OutPutCacheWithVaryByCustom
</asp:HyperLink>
<br />
<br />
<asp:HyperLink ID="HyperLink4" runat="server"
NavigateUrl="~/OutputCacheWithParam.aspx?id=1">OutPutCacheWithVaryByPar
am(The QueryString value is 1.)</asp:HyperLink>
<br />
<asp:HyperLink ID="HyperLink5" runat="server"
NavigateUrl="~/OutputCacheWithParam.aspx?id=2">OutPutCacheWithVaryByPar
am(The QueryString value is 2.)</asp:HyperLink>
</form>
</body>
</html>

b. OutPutCacheWithDuration.aspx
<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="OutputCacheWithDuration.aspx.cs"
Inherits="OutputCacheWithDuration" %>
<%@ OutputCache Duration="10" VaryByParam="none" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="lblResult" runat="server"></asp:Label>
<br />
<br />
<asp:Button ID="btnPostBack" runat="server" Text="Post Back" />
<p>
The page will be cached 10s, and then you can click Button to update
datetime.
</p>
</div>
<asp:HyperLink ID="HyperLink5" runat="server"
NavigateUrl="~/Default.aspx">Back To Default Page</asp:HyperLink>
</form>
</body>
</html>
c. OutPutCacheWithDuration.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 OutputCacheWithDuration : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
lblResult.Text = DateTime.Now.ToString();
}
}

d. OutputCacheWithControl.aspx
<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="OutputCacheWithControl.aspx.cs" Inherits="OutputCacheWithControl"
%>
<%@ OutputCache Duration="1000" VaryByControl="ddlOption" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="lblResult" runat="server"></asp:Label>
<br />
<br />
<asp:DropDownList ID="ddlOption" runat="server" AutoPostBack="True"
OnSelectedIndexChanged="ddlOption_SelectedIndexChanged">
<asp:ListItem Selected="True">Option One</asp:ListItem>
<asp:ListItem>Option Two</asp:ListItem>
<asp:ListItem>Option Three</asp:ListItem>
</asp:DropDownList>
<p>
The page will be rendered from cache basing on the selected item of
DropDownList.
The different item has corresponding cache.
</p>
</div>
<asp:HyperLink ID="HyperLink5" runat="server"
NavigateUrl="~/Default.aspx">Back To Default Page</asp:HyperLink>
</form>
</body>
</html>
e. OutputCacheWithControl.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 OutputCacheWithControl : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
lblResult.Text = DateTime.Now.ToString();
}
}
protected void ddlOption_SelectedIndexChanged(object sender, EventArgs e)
{
lblResult.Text = DateTime.Now.ToString() + " <br /> " +
ddlOption.SelectedValue;
}
}

f. OutputCacheWithCustom.aspx
<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="OutputCacheWithCustom.aspx.cs" Inherits="OutputCacheWithCustom"
%>
<%@ OutputCache Duration="1000" VaryByCustom="browser"
VaryByParam="none" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="lblResult" runat="server"></asp:Label>
<br />
<br />
<asp:Button ID="btnPostBack" runat="server" Text="Post Back" />
<p>
The page will be rendered from cache basing on the version of browser,
such as IE and FireFox.
</p>
</div>
<asp:HyperLink ID="HyperLink5" runat="server"
NavigateUrl="~/Default.aspx">Back To Default Page</asp:HyperLink>
</form>
</body>
</html>

g. OutputCacheWithCustom.aspx
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class OutputCacheWithCustom : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
lblResult.Text = DateTime.Now.ToString();
}
}
h. OutputCacheWithParam.aspx
<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="OutputCacheWithParam.aspx.cs" Inherits="OutputCacheWithParam"
%>
<%@ OutputCache Duration="1000" VaryByParam="id" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="lblResult" runat="server"></asp:Label>
<p>
The page will be rendered from cache until the value of QueryString
named "id" is
changed or Duration is expiration.
</p>
</div>
<asp:HyperLink ID="HyperLink5" runat="server"
NavigateUrl="~/Default.aspx">Back To Default Page</asp:HyperLink>
</form>
</body>
</html>

i. OutputCacheWithParam.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 OutputCacheWithParam : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
lblResult.Text = DateTime.Now.ToString();
}
}
Application_state

1.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>
  <system.web>
    <sessionState mode="InProc" timeout="20" cookieless="true"></sessionState>
    <compilation debug="true" targetFramework="4.5" />
  </system.web>

</configuration>

2.webform.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="Application_state.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>
    
    </div>
    </form>
</body>
</html>

3.webform.aspx.cs

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

namespace Application_state
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.Write("The num of users online=" + Application["user"].ToString());
        }
    }
}

4.global.asax.cs

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

namespace Application_state
{
    public class Global : System.Web.HttpApplication
    {

        protected void Application_Start(object sender, EventArgs e)
        {          
            Application["user"] = 0;
        }

        protected void Session_Start(object sender, EventArgs e)
        {            
            Application.Lock();
            Application["user"] = (int) Application["user"]+1;
            Application.UnLock();
        }

        protected void Application_BeginRequest(object sender, EventArgs e)
        {

        }

        protected void Application_AuthenticateRequest(object sender, EventArgs e)
        {

        }

        protected void Application_Error(object sender, EventArgs e)
        {

        }

        protected void Session_End(object sender, EventArgs e)
        {         
            Application.Lock();
            Application["user"] = (int)Application["user"] - 1;
            Application.UnLock();
        }

        protected void Application_End(object sender, EventArgs e)
        {

        }
    }
}


cookies

1.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>

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

</configuration>


2.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">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <table>
                <tr>
                    <td>
                        <asp:Button runat="server" ID="btn_create" Text="Create Cookie" OnClick="btn_create_Click" /></td>
                    <td>
                        <asp:TextBox runat="server" ID="txt_create"></asp:TextBox></td>
                    <td>
                        <asp:Label runat="server" ID="Label1"></asp:Label></td>
                </tr>
                <tr>
                    <td>
                        <asp:Button runat="server" ID="btn_ret" Text="Retrieve Cookie" OnClick="btn_ret_Click" /></td>
                    <td>
                        <asp:TextBox runat="server" ID="txt_ret"></asp:TextBox></td>
                </tr>
            </table>
        </div>
    </form>
</body>
</html>

3.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 btn_create_Click(object sender, EventArgs e)
    {
        Response.Cookies["name"].Value = txt_create.Text;
        Response.Cookies["name"].Expires = DateTime.Now.AddMinutes(1);
        Label1.Text = "Cookie Created";
        txt_create.Text = "";
    }
    protected void btn_ret_Click(object sender, EventArgs e)
    {
        if (Request.Cookies["name"] == null)
        {
            txt_ret.Text = "No cookie found";
        }
        else
        {
            txt_ret.Text = Request.Cookies["name"].Value;
        }

    }
}


QUERYSTRING

1 wen.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>

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

</configuration>


2.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">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <table>
                <tr>
                    <td>USERNAME </td>
                    <td>
                        <asp:TextBox runat="server" ID="txt_unm"></asp:TextBox></td>
                </tr>
                <tr>
                    <td>EMAIL </td>
                    <td>
                        <asp:TextBox runat="server" ID="txt_email"></asp:TextBox></td>
                </tr>
                <tr>
                    <td>
                        <asp:Button runat="server" ID="btn_submit" Text="LOGIN" OnClick="btn_submit_Click" /></td>
                </tr>
            </table>
        </div>
    </form>
</body>
</html>


3.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 btn_submit_Click(object sender, EventArgs e)
    {
        Response.Redirect("main.aspx?name=" + txt_unm.Text + "&email=" + txt_email.Text);
    }
}

4.main.aspx

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

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <table>
                <tr>
                    <td>
                        <asp:Label runat="server" ID="lbl_unm"></asp:Label></td>
                    <td>
                        <asp:Label runat="server" ID="lbl_email"></asp:Label></td>
                </tr>
            </table>

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



5.main.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 main : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        lbl_unm.Text = "Name = " + Request.QueryString["name"].ToString();
        lbl_email.Text = "Email = " + Request.QueryString["email"].ToString();
    }
}


session

1.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>

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

    <sessionState timeout="2"></sessionState>

  </system.web>

</configuration>

2.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">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <table>
                <tr>
                    <td>USERNAME</td>
                    <td>
                        <asp:TextBox runat="server" ID="txt_unm"></asp:TextBox></td>
                </tr>
                <tr>
                    <td>PASSWORD</td>
                    <td>
                        <asp:TextBox runat="server" ID="txt_pass" TextMode="Password"></asp:TextBox></td>
                </tr>
                <tr>
                    <td>
                        <asp:Button runat="server" ID="btn_login" Text="LOGIN" OnClick="btn_login_Click" /></td>
                </tr>
                <tr>
                    <td>
                        <asp:Label runat="server" ID="lbl"></asp:Label></td>
                </tr>
            </table>
        </div>
    </form>
</body>
</html>



3.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 btn_login_Click(object sender, EventArgs e)
    {
        if (txt_unm.Text == "ND" && txt_pass.Text == "ND")
        {
            Session["uname"] = txt_unm.Text;
            Response.Redirect("Main.aspx");
        }
        else
        {
            lbl.Text = "Invalid detail";
        }
    }
}

4.main.aspx

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

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <asp:Label runat="server" ID="lblname"></asp:Label>
            <br />
            <asp:Button runat="server" ID="btn_logout" Text="Logout" OnClick="btn_logout_Click" />
        </div>
    </form>
</body>
</html>



5.main.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 main : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["uname"] == null)
        {
            Response.Redirect("Login.aspx");
        }
        else
        {
            lblname.Text = "Welcome " + Session["uname"].ToString();
        }
    }
    protected void btn_logout_Click(object sender, EventArgs e)
    {
        Session["uname"] = null;
        Response.Redirect("Default.aspx");
    }
}


viewstate

1.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>

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

</configuration>


2.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">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <table>
            <tr>
                <td>UserName:</td>
                <td>
                    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></td>
            </tr>
            <tr>
                <td>Email:</td>
                <td>
                    <asp:TextBox ID="TextBox2" runat="server" ></asp:TextBox></td>
            </tr>
            <tr>
                <td>
                    <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Submit" />

                </td>
                <td>
                    <asp:Button ID="Button3" runat="server" OnClick="Button3_Click" Text="Restore" /></td>
            </tr>
        </table>



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


3.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 Button1_Click(object sender, EventArgs e)
    {

        ViewState["name"] = TextBox1.Text;
        ViewState["email"] = TextBox2.Text;

        TextBox1.Text = TextBox2.Text = string.Empty;
    }
    protected void Button3_Click(object sender, EventArgs e)
    {

        if (ViewState["name"] != null)
        {
            TextBox1.Text = ViewState["name"].ToString();
        }

        if (ViewState["email"] != null)
        {
            TextBox2.Text = ViewState["email"].ToString();
        }
    }
}

customValidator

1.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>

  <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />
  </system.web>
  <appSettings>
    <add key="ValidationSettings:UnobtrusiveValidationMode" value="None" />
  </appSettings>

</configuration>


2.deafult.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">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <asp:Label ID="Label1" runat="server" Text="User ID:"></asp:Label>
            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>

            <asp:CustomValidator ID="CustomValidator1" runat="server" OnServerValidate="UserCustomValidate"
                ControlToValidate="TextBox1"
                ErrorMessage="User ID should have atleast a capital, small and digit and should be greater than 6 and less than 25 letters" SetFocusOnError="True"></asp:CustomValidator>
        </div>
        <asp:Button ID="Button1" runat="server" Text="Submit" OnClick="Button1_Click" />
    </form>


</body>
</html>


3.deafult.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 UserCustomValidate(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;
    }
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {

    }
}

file_upload

1.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>

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

  <system.webServer>
    <security>
      <requestFiltering>
        <requestLimits maxAllowedContentLength="15728640" ></requestLimits>
      </requestFiltering>
    </security>
  </system.webServer>
</configuration>


2.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">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <table>
                <tr>
                    <td>Select File :</td>
                    <td>
                        <asp:FileUpload ID="FileUpload1" runat="server" /></td>
                </tr>
                <tr>
                    <td>
                        <asp:Button ID="btnupload" runat="server" OnClick="btnupload_Click" Text="Upload" />
                    </td>
                </tr>
                <tr>
                    <td>
                        <asp:Label ID="Label1" runat="server" Font-Bold="True"></asp:Label>
                    </td>
                </tr>
            </table>
            <asp:Image runat="server" ID="img" />
        </div>
    </form>
</body>
</html>


3.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 btnupload_Click(object sender, EventArgs e)
    {
        if (FileUpload1.HasFile)
        {
            FileUpload1.SaveAs(Server.MapPath("~/img/") + FileUpload1.FileName);
            img.ImageUrl = "~/img/" + FileUpload1.FileName;
            Label1.Text = "Image Uploaded Successfully !!";
        }
        else
        {
            Label1.Text = "Select image first !!";
        }
    }
}

login_with_validation_summary

1.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>

  <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />
  </system.web>
  <appSettings>
    <add key="ValidationSettings:UnobtrusiveValidationMode" value="None" />
  </appSettings>
</configuration>


2.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">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
        </div>
        <table>
            <tr>
                <td>User Name</td>
                <td>
                    <asp:TextBox ID="txt_username" runat="server"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="user" runat="server" ControlToValidate="txt_username"
                        ErrorMessage="Please enter a user name" ForeColor="Red">*</asp:RequiredFieldValidator>
                </td>
            </tr>
            <tr>
                <td>Password</td>
                <td>
                    <asp:TextBox ID="txt_password" runat="server"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="pass" runat="server" ControlToValidate="txt_password"
                        ErrorMessage="Please enter a password" ForeColor="Red">*</asp:RequiredFieldValidator>
                </td>
            </tr>
            <tr>
                <td>
                    <br />
                    <asp:Button ID="Button1" runat="server" Text="login" />
                </td>
                <td>
                    <asp:ValidationSummary ID="ValidationSummary1" runat="server" ForeColor="Red" />
                    <br />
                </td>
            </tr>
        </table>
    </form>
</body>
</html>


3.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)
    {

    }
}

Reg_form_with

1.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>

  <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />
  </system.web>
  <appSettings>
    <add key="ValidationSettings:UnobtrusiveValidationMode" value="None" />
  </appSettings>
</configuration>


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

                <tr>
                    <td>
                        <asp:Label ID="Label1" runat="server" Text="User Name"></asp:Label>
                    </td>
                    <td>
                        <asp:TextBox ID="txt_username" runat="server"></asp:TextBox></td>
                    <td>
                        <asp:RequiredFieldValidator runat="server" ID="req_unm" ControlToValidate="txt_username" ErrorMessage="Please Enter Username"></asp:RequiredFieldValidator></td>
                </tr>
                <tr>
                    <td>
                        <asp:Label ID="Label6" runat="server" Text="Email ID"></asp:Label>
                    </td>
                    <td>
                        <asp:TextBox ID="txt_email" runat="server" TextMode="Email"></asp:TextBox></td>
                    <td>
                        <asp:RequiredFieldValidator runat="server" ID="req_email" ControlToValidate="txt_email" ErrorMessage="Please Enter EmailID"></asp:RequiredFieldValidator>
                        <asp:RegularExpressionValidator runat="server" ID="reg_email" ControlToValidate="txt_email" ErrorMessage="Please enter emailid in proper format" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator>
                    </td>
                </tr>
                <tr>
                    <td>
                        <asp:Label ID="Label2" runat="server" Text="Password"></asp:Label></td>
                    <td>
                        <asp:TextBox ID="txt_password" runat="server" TextMode="Password"></asp:TextBox></td>
                    <td>
                        <asp:RequiredFieldValidator runat="server" ID="req_pass" ControlToValidate="txt_password" ErrorMessage="Please Enter Password"></asp:RequiredFieldValidator></td>
                </tr>
                <tr>
                    <td>
                        <asp:Label ID="Label3" runat="server" Text="Confirm Password"></asp:Label></td>
                    <td>
                        <asp:TextBox ID="txt_con_pass" runat="server" TextMode="Password"></asp:TextBox></td>
                    <td>
                        <asp:RequiredFieldValidator runat="server" ID="req_con_pass" ControlToValidate="txt_con_pass" ErrorMessage="Please Enter Password"></asp:RequiredFieldValidator>
                        <asp:CompareValidator runat="server" ID="com_val" ControlToValidate="txt_con_pass" ControlToCompare="txt_password" ErrorMessage="password mismatched"></asp:CompareValidator>
                    </td>
                </tr>
                <tr>
                    <td>
                        <asp:Label ID="Label4" runat="server" Text="Gender"></asp:Label></td>
                    <td>
                        <asp:RadioButton ID="rdb_m" runat="server" GroupName="gender" Text="Male" />
                        <asp:RadioButton ID="rdb_f" runat="server" GroupName="gender" Text="Female" /></td>
                </tr>
                <tr>
                    <td>
                        <asp:Label ID="Label7" runat="server" Text="Date of Birth"></asp:Label>s</td>
                    <td>
                        <asp:TextBox runat="server" ID="txt_bdate" TextMode="Date"></asp:TextBox>
                    </td>
                </tr>

                <tr>
                    <td></td>
                    <td>
                        <br />
                        <asp:Button ID="btn_submit" runat="server" Text="Register" OnClick="btn_submit_Click" />
                    </td>
                </tr>
            </table>
            <asp:Label ID="message" runat="server" Font-Size="Medium" ForeColor="Red"></asp:Label>
        </div>
    </form>
    <table>
        <tr>
            <td>
                <asp:Label ID="ShowUserNameLabel" runat="server"></asp:Label></td>
            <td>
                <asp:Label ID="ShowUserName" runat="server"></asp:Label></td>
        </tr>
        <tr>
            <td>
                <asp:Label ID="ShowEmailIDLabel" runat="server"></asp:Label></td>
            <td>
                <asp:Label ID="ShowEmail" runat="server"></asp:Label></td>
        </tr>
        <tr>
            <td>
                <asp:Label ID="ShowGenderLabel" runat="server"></asp:Label></td>
            <td>
                <asp:Label ID="ShowGender" runat="server"></asp:Label></td>
        </tr>
        <tr>
            <td>
                <asp:Label ID="lbl_showbdate" runat="server"></asp:Label></td>
            <td>
                <asp:Label ID="showbdate" runat="server"></asp:Label></td>
        </tr>
    </table>
</body>
</html>


3.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 btn_submit_Click(object sender, EventArgs e)
    {
        message.Text = "Hello " + txt_username.Text + " ! ";
        message.Text = message.Text + " <br/> You have successfuly Registered with the following details.";
        ShowUserName.Text = txt_username.Text;
        ShowEmail.Text = txt_email.Text;
        if (rdb_m.Checked)
        {
            ShowGender.Text = rdb_m.Text;
        }
        else ShowGender.Text = rdb_f.Text;
        showbdate.Text = txt_bdate.Text;
        ShowUserNameLabel.Text = "User Name";
        ShowEmailIDLabel.Text = "Email ID";
        ShowGenderLabel.Text = "Gender";
        lbl_showbdate.Text = "Birth Date";
        txt_username.Text = "";
        txt_email.Text = "";
        rdb_f.Checked = false;
        rdb_m.Checked = false;        
    }
}

Reg_form_without

1. 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>

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


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

                <tr>
                    <td>
                        <asp:Label ID="Label1" runat="server" Text="User Name"></asp:Label>
                    </td>
                    <td>
                        <asp:TextBox ID="txt_username" runat="server"></asp:TextBox></td>
                   
                </tr>
                <tr>
                    <td>
                        <asp:Label ID="Label6" runat="server" Text="Email ID"></asp:Label>
                    </td>
                    <td>
                        <asp:TextBox ID="txt_email" 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="txt_password" 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="txt_con_pass" 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="rdb_m" runat="server" GroupName="gender" Text="Male" />
                        <asp:RadioButton ID="rdb_f" runat="server" GroupName="gender" Text="Female" /></td>
                </tr>
                <tr>
                    <td>
                        <asp:Label ID="Label7" runat="server" Text="Date of Birth"></asp:Label>s</td>
                    <td>
                        <asp:TextBox runat="server" ID="txt_bdate" TextMode="Date"></asp:TextBox>
                    </td>
                </tr>
                
                <tr>
                    <td></td>
                    <td>
                        <br />
                        <asp:Button ID="btn_submit" runat="server" Text="Register" OnClick="btn_submit_Click" />
                    </td>
                </tr>
            </table>
            <asp:Label ID="message" runat="server" Font-Size="Medium" ForeColor="Red"></asp:Label>
        </div>
    </form>
    <table>
        <tr>
            <td>
                <asp:Label ID="ShowUserNameLabel" runat="server"></asp:Label></td>
            <td>
                <asp:Label ID="ShowUserName" runat="server"></asp:Label></td>
        </tr>
        <tr>
            <td>
                <asp:Label ID="ShowEmailIDLabel" runat="server"></asp:Label></td>
            <td>
                <asp:Label ID="ShowEmail" runat="server"></asp:Label></td>
        </tr>
        <tr>
            <td>
                <asp:Label ID="ShowGenderLabel" runat="server"></asp:Label></td>
            <td>
                <asp:Label ID="ShowGender" runat="server"></asp:Label></td>
        </tr>
        <tr>
            <td>
                <asp:Label ID="lbl_showbdate" runat="server"></asp:Label></td>
            <td>
                <asp:Label ID="showbdate" runat="server"></asp:Label></td>
        </tr>
    </table>
</body>
</html>


3.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 btn_submit_Click(object sender, EventArgs e)
    {
        message.Text = "Hello " + txt_username.Text + " ! ";
        message.Text = message.Text + " <br/> You have successfuly Registered with the following details.";
        ShowUserName.Text = txt_username.Text;
        ShowEmail.Text = txt_email.Text;
        if (rdb_m.Checked)
        {
            ShowGender.Text = rdb_m.Text;
        }
        else ShowGender.Text = rdb_f.Text;
        showbdate.Text = txt_bdate.Text;
        ShowUserNameLabel.Text = "User Name";
        ShowEmailIDLabel.Text = "Email ID";
        ShowGenderLabel.Text = "Gender";
        lbl_showbdate.Text = "Birth Date";
        txt_username.Text = "";
        txt_email.Text = "";
        rdb_f.Checked = false;
        rdb_m.Checked = false;        
    }
}

Comments