1-5

  1,2)<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication8.WebForm1" %>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Static Web Page</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 0;
            padding: 0;
            background-color: #f4f4f4;
        }
        header {
            background-color: #333;
            color: white;
            padding: 20px;
            text-align: center;
        }
        nav {
            margin: 0;
            padding: 0;
            text-align: center;
        }
        nav ul {
            list-style-type: none;
        }
        nav ul li {
            display: inline;
            margin: 0 10px;
        }
        nav ul li a {
            text-decoration: none;
            color: #333;
        }
        main {
            padding: 2rem;
        }
        footer {
            background-color: #333;
            color: white;
            text-align: center;
            padding: 1rem;
            position: fixed;
            bottom: 0;
            width: 100%;
        }
    </style>
</head>
<body>
    <header>
        <h1>Welcome to My Static Page</h1>
    </header>
    <nav>
        <ul>
            <li><a href="#">Home</a></li>
            <li><a href="#">About</a></li>
            <li><a href="#">Services</a></li>
            <li><a href="#">Contact</a></li>
        </ul>
    </nav>
    <main>
        <h2>About This Page</h2>
        <p> lorem This is a simple static web page created as an example. You can modify the content 
            and styles as needed to suit your preferences.lorem This is a simple static web p
            age created as an example. You can modify the content and styles as needed
             to suit your preferenceslorem This is a simple static web page created as a
            n example. You can modify the content and styles as needed to suit your pref
            erenceslorem This is a simple static web page created as an example. 
            You can modify the content and styles as needed to suit your preferenceslore
            m This is a simple static web page created as an example. You can modify the c
            ontent and styles as needed to suit your preferenceslorem This is a simple static we
            b page created as an example. You can modify the content and styles as needed to suit
             your preferenceslorem This is a simple static web page created as an example. You ca
            n modify the content and styles as needed to suit your preferenceslorem This is a sim
            ple static web page created as an example. You can modify the content and styles as n
            eeded to suit your preferenceslorem This is a simple static web page created as an ex
            ample. You can modify the content and styles as needed to suit your preferenceslorem 
            This is a simple static web page created as an example. You can modify the content an
            d styles as needed to suit your preferenceslorem This is a simple static web page cre
            ated as an example. You can modify the content and styles as needed to suit your prefere
            nceslorem This is a simple static web page created as an example. You can modify the cont
            ent and styles as needed to suit your preferenceslorem This is a simple static web page c

            reated as an example. You can modify the content and styles as needed to suit your prefe
            renceslorem This is a simple static web page created as an example. You can modify the co
            ntent and styles as needed to suit your preferenceslorem This is a simple static web page c
            reated as an example. You can modify the content and styles as needed to suit your preferen
            ceslorem This is a simple static web page created as an example. You can modify the content an
            d styles as needed to suit your preferenceslorem This is a simple static web page created as a
            n example. You can modify the content and styles as needed to suit your preferenceslorem This i
            s a simple static web page created as an example. You can modify the content and styles as nee
            ded to suit your preferenceslorem This is a simple static web page created as an example. You 
            can modify the content and styles as needed to suit your preferenceslorem This is a simple stat
            ic web page created as an example. You can modify the content and styles as needed to suit your
             preferenceslorem This is a simple static web page created as an example. You can modify the co
            ntent and styles as needed to suit your preferenceslorem This is a simple static web page creat
            ed as an example. You can modify the content and styles as needed to suit your preferenceslore
            m This is a simple static web page created as an example. You can modify the content and style
            s as needed to suit your preferenceslorem This is a simple static web page created as an examp
            le. You can modify the content and styles as needed to suit your preferences</p>
    </main>

    <footer>
        <p>&copy; 2025 My Static Web Page</p>
    </footer>
</body>
</html>



4,3)<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style>
/*        body {
            font-family: Arial, sans-serif;
            background-color: #f4f4f4;
            padding: 20px;
        }
        .form-container {
            background-color: #fff;
            padding: 20px;
            border-radius: 5px;
            max-width: 600px;
            margin: 0 auto;
        }
        label {
            display: block;
            font-weight: bold;
            margin-bottom: 5px;
        }
        input, select, textarea {
            width: 100%;
            padding: 10px;
            border: 1px solid #ccc;
            border-radius: 3px;
            margin-bottom: 15px;
            box-sizing: border-box;
        }
        input[type="radio"] {
            width: auto;
        }
        .button-container {
            text-align: right;
        }
        .button-container input {
            padding: 10px 20px;
            background-color: #007bff;
            color: #fff;
            border: none;
            border-radius: 3px;
            cursor: pointer;
        }*/
    </style>
    <script>
        function validateForm() {
            var name = document.getElementById('<%= txtName.ClientID %>').value.trim();
            var email = document.getElementById('<%= txtEmail.ClientID %>').value.trim();
            var phone = document.getElementById('<%= txtPhone.ClientID %>').value.trim();
            var dob = document.getElementById('<%= txtDOB.ClientID %>').value.trim();
            var address = document.getElementById('<%= txtAddress.ClientID %>').value.trim();
            var gender = document.querySelector('input[name="Gender"]:checked');
            var country = document.getElementById('<%= ddcountry.ClientID %>').value;

            //if (name === "" || email === "" || phone === "" || dob === "" || address === "" || !gender || country === "") {
            //    alert("All fields are required.");
            //    return false;
            //}

            var emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
            if (!emailRegex.test(email)) {
                alert("Please enter a valid email address.");
                return false;
            }

            var phoneRegex = /^\d{10}$/;
            if (!phoneRegex.test(phone)) {
                alert("Please enter a valid 10-digit phone number.");
                return false;
            }

            return true;
        }
    </script>
</head>
<body>
    <div class="form-container">
        <form id="form1" runat="server" onsubmit="return validateForm();">
            <label for="txtName">Name</label>
            <asp:TextBox ID="txtName" runat="server"></asp:TextBox>
            <br />

            <label for="txtEmail">Email</label>
            <asp:TextBox ID="txtEmail" runat="server"></asp:TextBox>
            <br />

            <label for="txtPhone">Phone Number</label>
            <asp:TextBox ID="txtPhone" runat="server"></asp:TextBox>
            <br />

            <label for="txtDOB">Date of Birth</label>
            <asp:TextBox ID="txtDOB" runat="server" TextMode="Date"></asp:TextBox><br />

            <label for="txtAddress">Address</label>
            <asp:TextBox ID="txtAddress" runat="server" TextMode="MultiLine" Rows="4"></asp:TextBox>
            <br />
            <label>Gender</label>
            <asp:RadioButton ID="rbtmale" runat="server" GroupName="Gender" Text="Male" />
            <asp:RadioButton ID="rbtfemale" runat="server" GroupName="Gender" Text="Female" />
            <br />
            <label for="ddcountry">Country</label>
            <asp:DropDownList ID="ddcountry" runat="server">
                <asp:ListItem Value="">Select Country</asp:ListItem>
                <asp:ListItem Value="INDIA">India</asp:ListItem>
                <asp:ListItem Value="SRILANKA">Sri Lanka</asp:ListItem>
                <asp:ListItem Value="PAKISTAN">Pakistan</asp:ListItem>
            </asp:DropDownList>
            <br />
            <br />

            <div class="button-container">
                <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Submit" />
            </div>
        </form>
    </div>
</body>
</html>
------------------------------------------------
5)<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %>


<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
    <style>
/*        body {
            font-family: Arial, sans-serif;
            background-color: #f4f4f4;
            padding: 20px;
        }
        .form-container {
            background-color: #fff;
            padding: 20px;
            border-radius: 5px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
            max-width: 600px;
            margin: 0 auto;
        }
        .form-container div {
            margin-bottom: 15px;
        }
        label {
            display: block;
            font-weight: bold;
            margin-bottom: 5px;
        }
        input[type="text"],
        input[type="email"],
        input[type="date"],
        textarea,
        select {
            width: 100%;
            padding: 10px;
            border: 1px solid #ccc;
            border-radius: 3px;
            box-sizing: border-box;
        }
        input[type="radio"] {
            margin-right: 10px;
        }
        .button-container {
            text-align: right;
        }
        .button-container input {
            padding: 10px 20px;
            background-color: #007bff;
            color: #fff;
            border: none;
            border-radius: 3px;
            cursor: pointer;
        }
        .button-container input:hover {
            background-color: #0056b3;
        }*/
    </style>
</head>
<body>
    <div class="form-container">
        <form id="form1" runat="server">
            <div>
                <label for="txtName">Name</label>
                <asp:TextBox ID="txtName" runat="server"></asp:TextBox>
            </div>
            <div>
                <label for="txtEmail">Email</label>
                <asp:TextBox ID="txtEmail" runat="server"></asp:TextBox>
            </div>
            <div>
                <label for="txtPhone">Phone Number</label>
                <asp:TextBox ID="txtPhone" runat="server"></asp:TextBox>
            </div>
            <div>
                <label for="txtDOB">Date of Birth</label>
                <asp:TextBox ID="txtDOB" runat="server" TextMode="Date"></asp:TextBox>
            </div>
            <div>
                <label for="txtAddress">Address</label>
                <asp:TextBox ID="txtAddress" runat="server" TextMode="MultiLine" Rows="4"></asp:TextBox>
            </div>
            <div>
                <label>Gender</label>
                <asp:RadioButton ID="rbtnMale" runat="server" GroupName="Gender" Text="Male" />
                <asp:RadioButton ID="rbtnFemale" runat="server" GroupName="Gender" Text="Female" />
                <asp:RadioButton ID="rbtnOther" runat="server" GroupName="Gender" Text="Other" />
            </div>
            <div>
                <label for="ddlCountry">Country</label>
                <asp:DropDownList ID="ddlCountry" runat="server">
                    <asp:ListItem Value="">Select Country</asp:ListItem>
                    <asp:ListItem Value="INDIA">India</asp:ListItem>
                    <asp:ListItem Value="SRILANKA">Sri Lanka</asp:ListItem>
                    <asp:ListItem Value="PAKISTAN">Pakistan</asp:ListItem>
                </asp:DropDownList>
            </div>
            <div class="button-container">
                <asp:Button ID="btnSubmit" runat="server" OnClick="btnSubmit_Click" Text="Submit" />
            </div>
        </form>
    </div>
</body>
</html>

.cs
using System;

namespace WebApplication1
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            // Page load logic (if any)
        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            // Server-side validation
            bool isValid = true;

            // Validate Name
            if (string.IsNullOrWhiteSpace(txtName.Text))
            {
                isValid = false;
                Response.Write("<p style='color:red;'>Name is required.</p>");
            }

            // Validate Email
            if (string.IsNullOrWhiteSpace(txtEmail.Text))
            {
                isValid = false;
                Response.Write("<p style='color:red;'>Email is required.</p>");
            }
            else if (!System.Text.RegularExpressions.Regex.IsMatch(txtEmail.Text, @"^[^@\s]+@[^@\s]+\.[^@\s]+$"))
            {
                isValid = false;
                Response.Write("<p style='color:red;'>Invalid email format.</p>");
            }

            // Validate Gender
            if (!rbtnMale.Checked && !rbtnFemale.Checked && !rbtnOther.Checked)
            {
                isValid = false;
                Response.Write("<p style='color:red;'>Please select your gender.</p>");
            }

            // Validate Country
            if (ddlCountry.SelectedValue == "")
            {
                isValid = false;
                Response.Write("<p style='color:red;'>Please select a country.</p>");
            }

            // If all validations pass
            if (isValid)
            {
                // Retrieve and display user input
                string name = txtName.Text;
                string email = txtEmail.Text;
                string gender = rbtnMale.Checked ? "Male" : rbtnFemale.Checked ? "Female" : "Other";
                string country = ddlCountry.SelectedValue;

                Response.Write("<h3>Registration Successful!</h3>");
                Response.Write("Name: " + name + "<br/>");
                Response.Write("Email: " + email + "<br/>");
                Response.Write("Gender: " + gender + "<br/>");
                Response.Write("Country: " + country + "<br/>");
            }
        }
    }
}

Comments

Popular posts from this blog

RDBMS

.Net