Hello, Team. I am stuck here at the finish-line on this program, I am trying to create a Click event handler for the Confirm button to save the “txtSales”, “lblDiscountAmount”, and “lblTotalPrice” in session state. Once the Confirm button is clicked it will take the user to the Confirmation page (page 2) where it will display what was inputted by the user on the first page.
Here is what I have on the Default.aspx page (just a snippet of the form)
<label>Sales price</label>
<asp:TextBox ID="txtSalesPrice" runat="server" CssClass="entry">100</asp:TextBox>
<label>Discount percent</label>
<asp:TextBox ID="txtDiscountPercent" runat="server" CssClass="entry">20</asp:TextBox>
<label>Discount amount</label>
<asp:Label ID="lblDiscountAmount" runat="server" CssClass="result"></asp:Label><br /><br />
<label>Total price</label>
<asp:Label ID="lblTotalPrice" runat="server" CssClass="result" ></asp:Label><br /><br />
<asp:Button ID="btnCalculate" runat="server" Text="Calculate"
OnClick="btnCalculate_Click" CssClass="button" />
<asp:Button ID="Button1" runat="server" CssClass="button" Text="Confirm" PostBackUrl="~/Confirm.aspx" OnClick="Button1_Click" />
Here is the code behind for my Default.aspx for the Confirm button
protected void Button1_Click(object sender, EventArgs e)
{
Response.Redirect("Confirm.aspx?" + TextBox.txtSalesPrice);
Response.Redirect("Confirm.aspx?") + Label.lblDiscountAmount);
Response.Redirect("Confirm.aspx?") + label.lblTotalPrice);
}
This is my Confirm.aspx page code snippet
<h1>Quotation confirmation</h1>
<label>Sales price</label><asp:Label ID="lblSalesPrice" runat="server" CssClass="result"></asp:Label><br /><br />
<label>Discount amount</label><asp:Label ID="lblDiscountAmount" runat="server" CssClass="result"></asp:Label><br /><br />
<label>Total price</label><asp:Label ID="lblTotalPrice" runat="server" CssClass="result"></asp:Label><br />
This is my code behind for my Confirm.aspx
protected void Page_Load(object sender, EventArgs e)
{
if (ViewState["SalesPrice"] && ["DiscountAmount"] && ["TotalPrice"] != null)
lblSalesPrice.Text = ViewState["SalesPrice"].ToString();
lblDiscountAmount.Text = ViewState["DiscountPrice"].ToString();
lblTotalPrice.Text = ViewState["TotalPrice"].ToString();
}
protected void DisplayItems(object sender, EventArgs e)
{
if (PreviousPage != null)
{
TextBox txtSalesPrice = (TextBox)PreviousPage.FindControl("txtSalesPrice");
lblSalesPrice.Text = txtSalesPrice.Text;
TextBox txtDiscountAmount = (TextBox)PreviousPage.FindControl("txtDiscountAmount");
lblDiscountAmount.Text = txtDiscountAmount.Text;
TextBox txtTotalPrice = (TextBox)PreviousPage.FindControl("txtTotalPrice");
lblTotalPrice.Text = txtTotalPrice.Text;
}
}
I have read my book and have done a lot of research online. I have even watched a couple YouTube videos. The problem is that it is still not working. I enjoy learning new languages and this is one of them. Yes, I am new to this but I should still have the logic down. Any help, someone, please.