How can I get the lblmessage to display only if Confirm button is clicked before Calculate button?

Do you think you could help me @WebMachine?

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.Collections.Generic;
using System.Linq;
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)
        {
            Button1.Enabled = true;
            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";
            }
        }
    }
}

I am not sure I know what you want.

I had a Default.aspx and I added the following to it:

<asp:Button ID="btnCalculate" runat="server" Text="Calculate" OnClick="BtnCalculate_Click"/>
<asp:Button ID="btnConfirm" runat="server" Text="Confirm" OnClick="BtnConfirm_Click" Enabled="False" />

And I have the following code:

protected void BtnCalculate_Click(object sender, EventArgs e)
{
    btnConfirm.Enabled = true;
    Session["SalesPrice"] = "$99";
}

protected void BtnConfirm_Click(object sender, EventArgs e)
{
    if (Session["SalesPrice"] != null)
    {
        Response.Redirect("Confirm.aspx");
    }
    else
    {
        TextBox1.Text = "Click the Calculate button before you click confirm";
    }
}

And I think that works. I click the Calculate button and then the Confirm button is enabled and I click that and then it goes to the Confirm.aspx.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.