.NET Practical Slip 23 Q B

Answer:

Default.aspx:

<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="validationinasp._Default" %>

<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
    <main>
        <table style="width: 66%;">
            <tr>
                <td class="style1" colspan="3" align="center">
                    <asp:Label ID="lblmsg" Text="Registration Form" runat="server" />
                </td>
            </tr>

            <tr>
                <td class="style3">Candidate:</td>
                <td class="style2">
                    <asp:DropDownList ID="ddlcandidate" runat="server" style="width:239px">
                        <asp:ListItem>Please Choose a Candidate</asp:ListItem>
                        <asp:ListItem>M H Kabir</asp:ListItem>
                        <asp:ListItem>Steve Taylor</asp:ListItem>
                        <asp:ListItem>John Abraham</asp:ListItem>
                        <asp:ListItem>Venus Williams</asp:ListItem>
                    </asp:DropDownList>
                </td>
                <td></td>
            </tr>

            <tr>
                <td class="style3">Email:</td>
                <td class="style2">
                    <asp:TextBox ID="txtemail" runat="server" style="width:250px"></asp:TextBox>
                </td>
                <td></td>
            </tr>

            <tr>
                <td class="style3">Password:</td>
                <td class="style2">
                    <asp:TextBox ID="TextBox2" runat="server" TextMode="Password"></asp:TextBox>
                </td>
                <td></td>
            </tr>

            <tr>
                <td class="style3">Confirm Password:</td>
                <td class="style2">
                    <asp:TextBox ID="TextBox3" runat="server" TextMode="Password"></asp:TextBox>
                </td>
                <td></td>
            </tr>

            <tr>
                <td class="style3">User ID:</td>
                <td class="style2">
                    <asp:TextBox ID="txtUserID" runat="server" style="width:250px"></asp:TextBox>
                </td>
                <td></td>
            </tr>

            <tr>
                <td class="style3">Name:</td>
                <td class="style2">
                    <asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
                </td>
                <td></td>
            </tr>

            <tr>
                <td class="style3">Age:</td>
                <td class="style2">
                    <asp:TextBox ID="txtAge" runat="server"></asp:TextBox>
                </td>
                <td></td>
            </tr>

            <tr>
                <td class="style3" align="center" colspan="3">
                    <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Register" />
                </td>
            </tr>
        </table>
    </main>
</asp:Content>

Default.aspx.cs:

using System;
using System.Web.UI;

namespace validationinasp
{
    public partial class _Default : Page
    {
        protected void Button1_Click(object sender, EventArgs e)
        {
            string name = TextBox4.Text;
            string userId = txtUserID.Text;
            string email = txtemail.Text;
            string password = TextBox2.Text;
            string confirmPassword = TextBox3.Text;
            string age = txtAge.Text;
            string candidate = ddlcandidate.SelectedValue;

            if (password == confirmPassword)
            {
                lblmsg.Text = "Registration successful!";
            }
            else
            {
                lblmsg.Text = "Passwords do not match.";
            }
        }
    }
}
Spread the love

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top