Web Application
1 WEB - Fibonnaci & Prime Number
Like
2 Create a registration form having text fields for accepting, Name, Age, Email,etc Perform validations
Like
3 Create a web application for user defined exception handling( DivideByZeroException and
IndexOutOfRangeException exceptions using textbox and label control)
Like
4 Create Web Form to demonstrate use of User Control. Create a label with college name and use
it in a webpage.
Like
5 Display the no. of visitors on a given web page.
Like
6 Create simple application to perform following operations (Pract 1d,2a)
i. Finding factorial Value
ii. Money Conversion
iii. Cube of given number
iv. Generate Fibonacci series
Like
7 Create Web Form to demonstrate use of Ad rotator Control with five advertisements. Also
demonstrate how keyword filter works.
Like
8 write and read a cookie from a clients computer.
Like
9 Create a web application to demonstrate Form Security and Windows Security with
proper Authentication and Authorization properties
Like
10 Master Page to maintain a consistent layout
across multiple content pages.
Like
11 Calendar control Vaction Selection.
Like
12 Create a web application to demonstrate various states of ASP.NET Pages.
Like
13 Create a simple web page to show data in Tree view control and datalist using web. Sitemap file
containing navigation information.
Like
Display the no. of visitors on a given web page.
Like
Display the no. of visitors on a given web page.
Like
//Defualt.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
Registration Form
Registration Form
Name:
Age:
Email:
Address:
Mobile:
//Defualt.aspx.cs
using System;
using System.Web.UI;
public partial class _Default : Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
if (Page.IsValid) // Check if all fields are valid
{
// Store the registration data in Session variables
Session["Name"] = txtName.Text;
Session["Age"] = txtAge.Text;
Session["Email"] = txtEmail.Text;
Session["Address"] = txtAddress.Text;
Session["Mobile"] = txtMobile.Text;
// Redirect to Default2.aspx
Response.Redirect("Default2.aspx");
}
}
protected void btnCancel_Click(object sender, EventArgs e)
{
// Clear all fields
txtName.Text = "";
txtAge.Text = "";
txtEmail.Text = "";
txtAddress.Text = "";
txtMobile.Text = "";
}
}
//Defualt2 .aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
Registration Success
Registration Successful!
Thank you for registering.
Your Data:
Name:
Age:
Email:
Address:
Mobile:
//Default2.aspx.cs
using System;
using System.Web.UI;
public partial class Default2 : Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
// Retrieve the registration data from Session and display it
lblName.Text = Session["Name"] as string;
lblAge.Text = Session["Age"] as string;
lblEmail.Text = Session["Email"] as string;
lblAddress.Text = Session["Address"] as string;
lblMobile.Text = Session["Mobile"] as string;
}
}
}
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
Exception Handling Example
Divide By Zero Exception Handling
Numerator:
Denominator:
Index Out of Range Exception Handling
Enter an Index (0-4):
//Csharp Here
using System;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnDivide_Click(object sender, EventArgs e)
{
try
{
int numerator = int.Parse(txtNumerator.Text);
int denominator = int.Parse(txtDenominator.Text);
int result = numerator / denominator;
lblDivideResult.Text = "Result: " + result.ToString();
}
catch (DivideByZeroException)
{
lblDivideResult.Text = "Error: Division by zero is not allowed.";
}
catch (FormatException)
{
lblDivideResult.Text = "Error: Please enter valid numbers.";
}
catch (Exception ex)
{
lblDivideResult.Text = "Error: " + ex.Message;
}
}
protected void btnGetElement_Click(object sender, EventArgs e)
{
try
{
int[] numbers = { 10, 20, 30, 40, 50 };
int index = int.Parse(txtIndex.Text);
int element = numbers[index];
lblArrayResult.Text = "Element at index " + index + ": " + element.ToString();
}
catch (IndexOutOfRangeException)
{
lblArrayResult.Text = "Error: Index out of range. Please enter an index between 0 and 4.";
}
catch (FormatException)
{
lblArrayResult.Text = "Error: Please enter a valid number for the index.";
}
catch (Exception ex)
{
lblArrayResult.Text = "Error: " + ex.Message;
}
}
}
//web User Control
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="WebUserControl.ascx.cs" Inherits="CollegeName" %>
//web user Control ascxs.cs
using System;
public partial class CollegeName : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
lblCollegeName.Text = "Smt Devkiba MohanSinhji Chauhan College";
}
}
//defualt.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register Src="CollegeName.ascx" TagName="CollegeName" TagPrefix="uc" %>
College Name Example
Welcome to our College Website
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
Visitor Counter
//CSharp
using System;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Application["VisitorCount"] == null)
{
Application["VisitorCount"] = 1;
}
else
{
Application["VisitorCount"] = (int)Application["VisitorCount"] + 1;
}
lblVisitorCount.Text = "Number of visitors: " + Application["VisitorCount"].ToString();
}
}
}
//Defualt.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
Simple Operations App
Simple Operations Application
Factorial Calculation
Enter a Number:
Money Conversion (USD to INR)
Enter USD Amount:
Cube of a Number
Enter a Number:
Fibonacci Series
Enter Number of Terms:
//defualt.aspx.cs
using System;
using System.Text;
using System.Linq;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnFactorial_Click(object sender, EventArgs e)
{
int num;
if (int.TryParse(txtFactorial.Text, out num) && num >= 0)
{
lblFactorialResult.Text = "Factorial: " + Factorial(num).ToString();
}
else
{
lblFactorialResult.Text = "Please enter a valid non-negative integer.";
}
}
private int Factorial(int n)
{
if (n <= 1)
return 1;
else
return n * Factorial(n - 1);
}
protected void btnConvertMoney_Click(object sender, EventArgs e)
{
decimal usdAmount;
const decimal conversionRate = 82.5m;
if (decimal.TryParse(txtMoney.Text, out usdAmount) && usdAmount >= 0)
{
lblMoneyResult.Text = "INR: " + (usdAmount * conversionRate).ToString("F2");
}
else
{
lblMoneyResult.Text = "Please enter a valid amount.";
}
}
protected void btnCube_Click(object sender, EventArgs e)
{
int num;
if (int.TryParse(txtCube.Text, out num))
{
lblCubeResult.Text = "Cube: " + (num * num * num).ToString();
}
else
{
lblCubeResult.Text = "Please enter a valid integer.";
}
}
protected void btnFibonacci_Click(object sender, EventArgs e)
{
int terms;
if (int.TryParse(txtFibonacci.Text, out terms) && terms > 0)
{
lblFibonacciResult.Text = "Fibonacci Series: " + string.Join(", ", Fibonacci(terms).Select(i => i.ToString()).ToArray());
}
else
{
lblFibonacciResult.Text = "Please enter a valid positive integer.";
}
}
private int[] Fibonacci(int n)
{
int[] series = new int[n];
if (n >= 1) series[0] = 0;
if (n >= 2) series[1] = 1;
for (int i = 2; i < n; i++)
{
series[i] = series[i - 1] + series[i - 2];
}
return series;
}
}
//Defualt.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
AdRotator Example
//Defualt.aspx.cs
using System;
using System.Web.UI;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
AdRotator1.KeywordFilter = "Technology";
lblMessage.Text = "Current filtered for Technology ads";
}
}
protected void ChangeFilter(string keyword)
{
AdRotator1.KeywordFilter = keyword;
lblMessage.Text = "Currently filtered for {keyword} ads";
}
}
//Ads.xml
~/Images/ad1.jpg
http://www.google.com
Ad 1
Technology
50
~/Images/ad2.jpg
http://www.google.com
Ad 2
Sports
30
~/Images/ad3.jpg
http://www.google.com
Ad 3
Technology
40
~/Images/ad4.jpg
http://www.google.com
Ad 4
Fashion
20
~/Images/ad5.jpg
http://www.google.com
Ad 5
Sports
10
//Defualt.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
Cookie Example
Write and Read Cookie Example
//defualt.aspx.cs
using System;
using System.Web;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnWriteCookie_Click(object sender, EventArgs e)
{
HttpCookie userCookie = new HttpCookie("UserInfo");
userCookie["Username"] = "RahulYadav";
userCookie["Email"] = "rahul.yadav@gmail.com";
userCookie.Expires = DateTime.Now.AddDays(1);
Response.Cookies.Add(userCookie);
lblResult.Text = "cookie write ho gya !";
}
protected void btnReadCookie_Click(object sender, EventArgs e)
{
if (Request.Cookies["UserInfo"] != null)
{
HttpCookie userCookie = Request.Cookies["UserInfo"];
string username = userCookie["Username"];
string email = userCookie["Email"];
lblResult.Text = String.Format("Cookie Get: Username = {0}, Email = {1}", username, email);
}
else
{
lblResult.Text = "No cookie found!";
}
}
}
//Defualt .aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
Login Page
Login Page
login through your login windows login data
//Defualt.aspx.cs
using System;
using System.Web.UI;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (User.Identity.IsAuthenticated)
{
Response.Redirect("Default2.aspx");
}
}
}
//Defualt2.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="_Default2" %>
Home Page
Welcome to the Application
This page is avialable for log users only
//defualt.aspx.cs
using System;
using System.Web.UI;
public partial class _Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Response.Write("Welcome, " + User.Identity.Name);
}
}
//web.congig
//MasterPage.master
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="MasterPage" %>
Master Page Demo
Indian Events
Footer
//Defualt.aspx
<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" Title="Untitled Page" %>
Welcome to Indian Cultural Events
//default2.apsx
<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" Title="Untitled Page" %>
Happy Diwali
//defualt3.aspx
<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" Title="Untitled Page" %>
Happy Holi
//default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
Vacation Planner
Select Your Vacation Dates
Start Date:
End Date:
Vacation Summary:
Start Date:
End Date:
Total Vacation Days:
//Defualt.aspx.cs
using System;
using System.Web.UI;
public partial class _Default : Page
{
DateTime startDate;
DateTime endDate;
protected void CalendarStart_SelectionChanged(object sender, EventArgs e)
{
startDate = CalendarStart.SelectedDate;
lblStartDate.Text = startDate.ToString("D");
}
protected void CalendarEnd_SelectionChanged(object sender, EventArgs e)
{
endDate = CalendarEnd.SelectedDate;
lblEndDate.Text = endDate.ToString("D");
}
protected void btnCalculate_Click(object sender, EventArgs e)
{
if (CalendarStart.SelectedDate != DateTime.MinValue && CalendarEnd.SelectedDate != DateTime.MinValue)
{
if (CalendarEnd.SelectedDate >= CalendarStart.SelectedDate)
{
int totalDays = (CalendarEnd.SelectedDate - CalendarStart.SelectedDate).Days + 1;
lblTotalDays.Text = totalDays.ToString();
}
else
{
lblTotalDays.Text = "Invalid: End date must be after or the same as start date!";
}
}
else
{
lblTotalDays.Text = "Please select both start and end dates.";
}
}
}
//Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
ASP.NET Page States Demo
ASP.NET Page States Demo
View State:
Session State:
Application State:
Postback State:
//Defualt.aspx.cs
using System;
using System.Web.UI;
public partial class _Default : Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
lblPostback.Text = "This is the initial load.";
}
else
{
lblPostback.Text = "Postback occurred.";
}
}
protected void btnSaveViewState_Click(object sender, EventArgs e)
{
ViewState["UserInput"] = txtViewState.Text;
lblViewState.Text = "ViewState saved: " + ViewState["UserInput"];
}
protected void btnSaveSessionState_Click(object sender, EventArgs e)
{
Session["UserInput"] = txtSessionState.Text;
lblSessionState.Text = "SessionState saved: " + Session["UserInput"];
}
protected void btnSaveApplicationState_Click(object sender, EventArgs e)
{
Application["UserInput"] = txtApplicationState.Text;
lblApplicationState.Text = "ApplicationState saved: " + Application["UserInput"];
}
protected void btnPostback_Click(object sender, EventArgs e)
{
lblPostback.Text = "Postback triggered.";
}
}
//Web.sitemap
//Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Default" %>
<%@ Register TagPrefix="asp" Namespace="System.Web.UI.WebControls" Assembly="System.Web" %>
TreeView and DataList Example
<%# Eval("Title") %>
<%# Eval("Description") %>
//Defualt.aspx.cs
using System;
using System.Data;
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
// Populate TreeView
TreeNode rootNode = new TreeNode("Root Node");
rootNode.ChildNodes.Add(new TreeNode("Child Node 1"));
rootNode.ChildNodes.Add(new TreeNode("Child Node 2"));
TreeView1.Nodes.Add(rootNode);
// Populate DataList
DataTable dt = new DataTable();
dt.Columns.Add("Title");
dt.Columns.Add("Description");
dt.Rows.Add("Item 1", "Description for Item 1");
dt.Rows.Add("Item 2", "Description for Item 2");
DataList1.DataSource = dt;
DataList1.DataBind();
}
}
}
//web.config
Comments
Post a Comment