Visitors and Validation
Visitors and Validation
No. Of Visitors
Code :
Aspx File
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Visitor Counter</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h1>Visitor Counter</h1>
C# File
using System;
namespace YourNamespace
{
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
// Increment the visitor count and display it
IncrementVisitorCount();
DisplayVisitorCount();
}
}
Validations
- first update the web.config file with adding the following tag init or
else you will get error!, add this inside the configuration tag
<appSettings>
<add key="ValidationSettings:UnobtrusiveValidationMode" value="None" />
</appSettings>
Registration aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Validations.aspx.cs"
Inherits="PracticalTest1.Validations" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Registration Form</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h1>Registration Form</h1>
<br />
<br />
<br />
<br />
<br />
</div>
</form>
</body>
</html>
Registration C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace PracticalTest1
{
public partial class Validations : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
// Display entered information on a new page
Response.Redirect($"ResultPage.aspx?
Name={txtName.Text}&Age={txtAge.Text}&Address={txtAddress.Text}&Mobile={txtMobile.Text}");
}
ResultPage aspx
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Registration Result</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h1>Registration Result</h1>
</div>
</form>
</body>
</html>
ResultPage C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace PracticalTest1
{
public partial class ResultPage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
// Retrieve information from query parameters
string name = Request.QueryString["Name"];
string age = Request.QueryString["Age"];
string address = Request.QueryString["Address"];
string mobile = Request.QueryString["Mobile"];
// Display the entered information
lblResult.Text = $"Name: {name}<br/>" +
$"Age: {age}<br/>" +
$"Address: {address}<br/>" +
$"Mobile Number: {mobile}";
}
}
}
}