Question

In: Computer Science

Web Application Development Course - C# Update the ASP.NET web application code by adding below functionality:...

Web Application Development Course - C#

Update the ASP.NET web application code by adding below functionality:

• Create a new web form called Welcome.aspx and add labels to show name, company, email, and membership.

• Create a new business layer class called Customer to hold the entered user details

• When the user clicks on Sign Up button and if all the validations on the page pass

o Store the details entered on page in the Customer object.

o Save the Customer object in Session State.

o Navigate to Welcome.aspx, read the Customer object from Session State and show the name, company, email and membership on this page using respective labels.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace PopQuiz4
{
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
UnobtrusiveValidationMode = UnobtrusiveValidationMode.None;

if (!IsPostBack)
{
radBtnFree.Checked = true;
ddlTimeZone.SelectedIndex = 0;
}
}

protected void radBtnFree_CheckedChanged(object sender, EventArgs e)
{
if (radBtnFree.Checked)
{
lblAmount.Text = "$0";
}
}

protected void radBtnBasic_CheckedChanged(object sender, EventArgs e)
{
if (radBtnBasic.Checked)
{
lblAmount.Text = "$30";
}
}

protected void radBtnPremium_CheckedChanged(object sender, EventArgs e)
{
if (radBtnPremium.Checked)
{
lblAmount.Text = "$60";
}
}

protected void CustValTxtEmail_ServerValidate(object source, ServerValidateEventArgs args)
{
if (txtEmail.Text.Contains(txtCompany.Text))
{
args.IsValid = true;
}
else
{
args.IsValid = false;
}
}

protected void btnSignup_Click(object sender, EventArgs e)
{
if (IsValid)
{
lblStatus.Text = "Sign up successful!";
lblStatus.ForeColor = System.Drawing.Color.Green;
}
}
}
}

Solutions

Expert Solution

Hi,

Please find the Class and pages below:

SignUp.aspx

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

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            Name:
            <asp:TextBox ID="txtName" runat="server" Height="20px" Width="200px"></asp:TextBox>
            <br />
        </div>
        <div>
            Company:
            <asp:TextBox ID="txtCompany" runat="server" Height="20px" Width="200px"></asp:TextBox>
            <br />
        </div>
        <div>
            Email:
            <asp:TextBox ID="txtEmail" runat="server" Height="20px" Width="200px"></asp:TextBox>
            <br />
        </div>
        <div>
            Membership:
            <asp:TextBox ID="txtMembership" runat="server" Height="20px" Width="200px"></asp:TextBox>
            <br />
        </div>

        <br /><br />
        <asp:Button Text="Sign Up" ID="btnSignUp" runat="server" Height="20px" Width="100px" OnClick="btnSignUp_Click" />
       
    </form>
</body>
</html>

SignUp.aspx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace DisplayInfoFromDB
{
    public partial class SignUp : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnSignUp_Click(object sender, EventArgs e)
        { //get the user input from text boxes to string variables
            string sUserName = txtName.Text.Trim();
            string sCompanyName = txtCompany.Text.Trim();
            string sEmail = txtEmail.Text.Trim();
            string sMembership = txtMembership.Text.Trim();

            if (IsValid)
            {
                //Instantiate Class of Customer
                Customer oCustomer = new Customer();

                //Set Propertis of Cusomer class using text entered by user
                oCustomer.UserName = sUserName;
                oCustomer.CompanyName = sCompanyName;
                oCustomer.Email = sEmail;
                oCustomer.Membership = sMembership;

                //Crate Session objecct
                Session["Customer"] = oCustomer;

                //Redirect to welcome page
                Response.Redirect("~/Welcome.aspx");

            }

           
        }
    }
}

Welcome.aspx

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

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
           Name:
            <asp:Label ID="lblName" runat="server" Height="20px" Width="200px"></asp:Label>
            <br />
        </div>
        <div>
            Company:
            <asp:Label ID="lblCompany" runat="server" Height="20px" Width="200px"></asp:Label>
            <br />
        </div>
        <div>
            Email:
            <asp:Label ID="lblEmail" runat="server" Height="20px" Width="200px"></asp:Label>
            <br />
        </div>
        <div>
            Membership:
            <asp:Label ID="lblMembership" runat="server" Height="20px" Width="200px"></asp:Label>
            <br />
        </div>
     
    </form>
</body>
</html>

Welcome.aspx.cs

using System;
using System.Data;
using System.Data.SqlClient;
using System.Runtime.InteropServices;

namespace DisplayInfoFromDB
{
    public partial class Welcome : Customer //IMplement the Custome Class 
    {
        /// <summary>
        /// Page Load Event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected override void Page_Load(object sender, EventArgs e)
        {
            //First call out base class's page load method and will check the session is live or not
            base.Page_Load(sender, e);

            //Call function to fetch data
            //here you are confirm that your session is live and session object is having data
            FetchInforAndDisplay();
        }

        /// <summary>
        /// Function to fetch data from database and display to form
        /// </summary>
        private void FetchInforAndDisplay()
        {
            try
            { //check session is not null
                if (!string.IsNullOrEmpty(Session["Customer"].ToString()))
                { //fetch the Object of Customer Class from Sesson variable and cast it to Customer type
                    Customer oCustomer = (Customer)Session["Customer"];
                    // fetch the data from the Custome Class session object and set it to form
                    lblName.Text = oCustomer.UserName;
                    lblCompany.Text = oCustomer.CompanyName;
                    lblEmail.Text = oCustomer.Email;
                    lblMembership.Text = oCustomer.Membership;
                }
                else { //IF sessin is is null then return user to signup page
                    Response.Redirect("~/SignUp.aspx");
                }

            }
            catch (Exception ex)
            { // if any exception then reutn uer to sign up page
                Response.Redirect("~/SignUp.aspx");
            }

        }



    }
}

Customer.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace DisplayInfoFromDB
{
    public class Customer : System.Web.UI.Page
    {
        public string UserName = string.Empty;
        public string CompanyName = string.Empty;
        public string Email = string.Empty;
        public string Membership = string.Empty;

        protected virtual void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if (Session["Customer"] != null && !string.IsNullOrEmpty(Session["Customer"].ToString()))
                {
                    //Her you can do the things to set application level
                }
                else
                {

                    //you need to create new login page here so once session is lost then it will rediret to the login page
                    //rigt now i have redirect it to sign up
                     //clears the session and redirect user to signup page
                    Session.Abandon();
                    Response.Redirect("~/SignUp.aspx");

                }
            }
            catch (Exception ex)
            {  //if any exeception comes the clear all the session and redirect user to signup page
                Session.Abandon();
                Response.Redirect("~/SignUp.aspx");
            }

        }



    }
}

Customer class is the Base Class for all your pages. If you are going to create any new pages in the application then that respected page's base class should be Customer Class. You can see the Welcome.aspx.cs Class which base class is Customer Class.

In this Customer Class, we have handled the Session i.e. we have checked that session is available then only return to that requested page otherwise you will be redirected to the login/sign-up page.

in the above application, if you directly browse the Welcome.aspx page, then it will redirect you to the signup page because the session is not created for the user.

Thanks


Related Solutions

describe the web development stack and the roles Angular and ASP.NET Core play as part of...
describe the web development stack and the roles Angular and ASP.NET Core play as part of it.
JAVA programming language Please add or modify base on the given code Adding functionality Add functionality...
JAVA programming language Please add or modify base on the given code Adding functionality Add functionality for multiplication (*) Adding JUnit tests Add one appropriately-named method to test some valid values for tryParseInt You will use an assertEquals You'll check that tryParseInt returns the expected value The values to test: "-2" "-1" "0" "1" "2" Hint: You will need to cast the return value from tryParseInt to an int e.g., (int) ValidationHelper.tryParseInt("1") Add one appropriately-named method to test some invalid...
For your final project, you are to create a two-page web application of your choice. ASP.NET...
For your final project, you are to create a two-page web application of your choice. ASP.NET : C# You must include the following items: At least 5 different standard server controls At least 2 validation controls At least 1 navigation control ~ one must navigate back and forth to each page One session state element Upon completion of your two-page web application, you will provide a two page report describing the functions of the web application as well as each...
C# & ASP.NET Create a console application that prompts the user to enter a regular expression,...
C# & ASP.NET Create a console application that prompts the user to enter a regular expression, and then prompts the user to enter some input and compare the two for a match until the user presses Esc: The default regular expression checks for at least one digit. Enter a regular expression (or press ENTER to use the default): ^[a- z]+$ Enter some input: apples apples matches ^[a-z]+$? True Press ESC to end or any key to try again. Enter a...
INTRODUCTION TO WEB APPLICATION DEVELOPMENT 1. Explain and apply the key features of advanced Web design...
INTRODUCTION TO WEB APPLICATION DEVELOPMENT 1. Explain and apply the key features of advanced Web design and programming features (MVC and Razor). 2. Create a web application by using web server controls, event handlers, application state, and session state. 3. Develop client-server applications with form validations using client-side scripting and server-side database connectivity. 4. Analyze security requirements and build websites with authentication and authorization features. 5. Develop service-oriented applications (SOAs) using web services and standard communication frameworks. 6. Enforce quality...
what will be the code in C programming for the client and server chat application for...
what will be the code in C programming for the client and server chat application for the below issue :- write the C Programming code that able client have a unique ID to be known by the server
Assignment - Store Design and code a HTML/CSS/JS based web application for your online store. Assignment...
Assignment - Store Design and code a HTML/CSS/JS based web application for your online store. Assignment Specification · Minimum of SIX web pages are required for this assignment: § One Landing/Container Page ( a page with logo) § One Home Page § Three or more Product Line Pages (pages with product and it information ) § One Order Page (for customer to order a product after view the profuct on the product page) · Build internal CSS style sheets in...
Complete the following C# code that declares an array of 7 integers. The application allows the...
Complete the following C# code that declares an array of 7 integers. The application allows the user three options: l. to view the elements of array in reverse order, from the last to first position, 2. to choose a specific position to view, 3. quit the program
4. What is the most popular application service? a. World Wide Web b. E-mail c. P2P...
4. What is the most popular application service? a. World Wide Web b. E-mail c. P2P d. eBay 9. The different top-level domains represent which of the following? (Choose all correct answers.) a. Type of organization b. Country of origin c. Company or brand name d. File server name
C# I need working code please Write a console application that accepts the following JSON as...
C# I need working code please Write a console application that accepts the following JSON as input: {"menu": { "header": "SVG Viewer", "items": [ {"id": "Open"}, {"id": "OpenNew", "label": "Open New"}, null, {"id": "ZoomIn", "label": "Zoom In"}, {"id": "ZoomOut", "label": "Zoom Out"}, {"id": "OriginalView", "label": "Original View"}, null, {"id": "Quality"}, {"id": "Pause"}, {"id": "Mute"}, null, {"id": "Find", "label": "Find..."}, {"id": "FindAgain", "label": "Find Again"}, {"id": "Copy"}, {"id": "CopyAgain", "label": "Copy Again"}, {"id": "CopySVG", "label": "Copy SVG"}, {"id": "ViewSVG", "label": "View...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT