.NET Practical Slip 11 Q A

Slip 11 Q.A) Problem Statement

Q. Write an ASP.Net program that gets user input such as the user name, mode of payment, and appropriate credit card. After the user enters the appropriate values, the Validation button validates the values entered. 15 Marks

Answer:

Default.aspx

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

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>

         <h2>User Payment Form</h2>

            <!-- User Name -->
            User Name :
            <asp:TextBox ID="txtName" runat="server"></asp:TextBox>
            <asp:RequiredFieldValidator 
                ID="rfvName" 
                runat="server" 
                ControlToValidate="txtName"
                ErrorMessage="User Name is required"
                ForeColor="Red">
            </asp:RequiredFieldValidator>

            <br /><br />

            <!-- Mode of Payment -->
            Mode of Payment :
            <asp:RadioButtonList ID="rblPayment" runat="server">
                <asp:ListItem>Cash</asp:ListItem>
                <asp:ListItem>Credit Card</asp:ListItem>
                <asp:ListItem>Debit Card</asp:ListItem>
            </asp:RadioButtonList>

            <asp:RequiredFieldValidator 
                ID="rfvPayment" 
                runat="server" 
                ControlToValidate="rblPayment"
                InitialValue=""
                ErrorMessage="Select Mode of Payment"
                ForeColor="Red">
            </asp:RequiredFieldValidator>

            <br />

            <!-- Credit Card Type -->
            Credit Card :
            <asp:DropDownList ID="ddlCard" runat="server">
                <asp:ListItem Value="">--Select Card--</asp:ListItem>
                <asp:ListItem>Visa</asp:ListItem>
                <asp:ListItem>MasterCard</asp:ListItem>
                <asp:ListItem>Rupay</asp:ListItem>
            </asp:DropDownList>

            <asp:RequiredFieldValidator 
                ID="rfvCard" 
                runat="server" 
                ControlToValidate="ddlCard"
                InitialValue=""
                ErrorMessage="Select Credit Card"
                ForeColor="Red">
            </asp:RequiredFieldValidator>

            <br /><br />

            <!-- Validation Button -->
            <asp:Button ID="btnValidate" 
                runat="server" 
                Text="Validate" />

            <br /><br />

            <asp:ValidationSummary 
                ID="ValidationSummary1" 
                runat="server" 
                ForeColor="Blue" />
    
    </div>
    </form>
</body>
</html>

Default.aspx.cs (Code Behind)

using System;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace slip_11
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            // Disable UnobtrusiveValidationMode to avoid jquery error
            UnobtrusiveValidationMode = UnobtrusiveValidationMode.None;
        }
    }
}

Helpful Links

Spread the love

Leave a Comment

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

Scroll to Top