Daron_1 0 AntonioMicheal

Hello Everyone,

I am building multi-web application pages using the Default.aspx, Default.aspx.cs and Confirm.aspx and Confirm.aspx.cs. The problem that I am having is that when I click "Confirm" before clicking "Calculate," the event handler displays the "Click the Calculate button before the confirm" at the bottom of the page. It does that even if the Calculate button is clicked before the Confirm and also displays again when I reload the page. How can I get this to only display if the session state value of SalesPrice is null? Otherwise, it will redirect to the confirm page. Here is Default.aspx.cs:

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

using System.Web.UI.WebControls;

namespace XEx04Quotation
{

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

        protected void btnCalculate_Click(object sender, EventArgs e)
        {
            if (IsValid)
            {
                decimal salesPrice = Convert.ToDecimal(txtSalesPrice.Text);

                // save the salesPrice into a session state variable 
                Session["SalesPrice"] = salesPrice;

                decimal discountPercent = Convert.ToDecimal(txtDiscountPercent.Text) / 100;

                decimal discountAmount = salesPrice * discountPercent;

                // save the discountAmount into a session state variable
                Session["Discount"] = discountAmount;

                decimal totalPrice = salesPrice - discountAmount;

                // save the totalPrice into a session state variable

                Session["TotalPrice"] = totalPrice;

                lblDiscountAmount.Text = discountAmount.ToString("c");
                lblTotalPrice.Text = totalPrice.ToString("c");
            }   
        }

        protected void Button1_Confirm(object sender, EventArgs e)
        {
             if(Session["SalesPrice"] != null)
            {
                Response.Redirect("Confirm.aspx");
            }
            else 
            {
                // This is the part I am concerned about
                lblmessage2.Text = "Click the Calculate button before you click confirm";
            }

        }
    }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.