Default.aspx.cs: using System; using System.Collections.Generic; using System.Li
ID: 3882156 • Letter: D
Question
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)
{
if (IsValid)
{
decimal salesPrice = Convert.ToDecimal(txtSalesPrice.Text);
decimal discountPercent = Convert.ToDecimal(txtDiscountPercent.Text) / 100;
decimal discountAmount = salesPrice * discountPercent;
decimal totalPrice = salesPrice - discountAmount;
lblDiscountAmount.Text = discountAmount.ToString("c");
lblTotalPrice.Text = totalPrice.ToString("c");
{
Session["Price"] = txtSalesPrice.Text;
Session["Discount"] = lblDiscountAmount.Text;
Session["Total"] = lblTotalPrice.Text;
}
}
}
protected void confirmButton_Click(object sender, EventArgs e)
{
Response.Redirect("~/Confirm.aspx");
}
}
}
Confirm.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 Confirm : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
UnobtrusiveValidationMode = UnobtrusiveValidationMode.None;
{
lblSalesPrice.Text = Convert.ToDecimal(Session["Price"]).ToString("c");
lblDiscountAmount.Text = Session["Discount"].ToString();
lblTotalPrice.Text = Session["Total"].ToString();
}
}
protected void sendbutton_Click(object sender, EventArgs e)
{
string name;
string email;
name = txtName.Text.ToString();
email = txtEmail.Text.ToString();
if (txtName != null && txtName != null)
{
lblMessage.Text = "Quotation sent to "+ name + " at " + email + ".";
}
else
lblMessage.Text = "Click the Send Quotation button to send the quotation email";
}
}
}
I am having trouble doing problems 10-13, I try to add the code but keep getting errors for the states.
6 Extra exercises for Murach's ASP.NET 4.6 with C# 2015 Extra 4-1 Enhance the the Quotation application The application for this exercise is an enhanced version of the one for exercise 3-1. First, the Quotation has a confirm button to the right of the Calculate button. Second, the Confirm button redirects to a Confirmation page The Quotation page (Default.aspx) Price quotation Sales price 150 Discount percent25 Discount amount $7.50 Total price Calcuiate Confrm Enter price and aunt amour and Click Catulale The Confirmation page (Confirm.aspx) Quotation confirmation Sales price $150.00 Discount amount $37.5 Total price $112.0 Send confirmation to Name Grace Hopper Email address e@yahoo com Send Quctaton Return Click the Send Quotation burton to send the quotation via ema Open the web application for this exercise and start enhancing its pages 1. Open the web application named XEx04Quotation in your exercises_extra folder. It includes the aspx and code-behind files for the pages shown above, but the first page doesn't have the code for the Confirm button and the second page doesn't have the 7Explanation / Answer
Ans: You didn't added the required field and regular field validation in the text, so I added the validation in the textbox control,so it will not allow the worng values.
I have added required field validation for text box contorl .
I have also added regular field validator for text box, so it will only allow numeric and decimal value in text box.
In this short code snippet article I will share the following Regular Expressions (Regex) for validating decimal numbers in TextBox.
1. Regular Expressions (Regex) to allow both decimals as wells as integers numbers.
2. Regular Expressions (Regex) to allow any decimal number starting from 1 upto N decimal places.
<asp:RegularExpressionValidator ID="Regex1" runat="server" ValidationExpression="((d+)((.d{1,2})?))$"
ErrorMessage="Please enter valid integer or decimal number with 2 decimal places."
ControlToValidate="TextBox1" />
Default.ascx code:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.button
{
background-color: #00bfff;
border: none;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
border-radius: 12px;
}
.header
{
background-color: #f1f1f1;
padding: 30px;
text-align: center;
font-size: 35px;
}
/* Create three unequal columns that floats next to each other */
.column
{
float: left;
padding: 10px;
height: 300px; /* Should be removed. Only for demonstration */
}
label
{
padding: 12px 12px 12px 0;
display: inline-block;
}
.col-25
{
float: left;
width: 25%;
margin-top: 6px;
}
.col-75
{
float: left;
width: 75%;
margin-top: 6px;
}
/* Clear floats after the columns */
.row:after
{
content: "";
display: table;
clear: both;
}
/* Left and right column */
.column.side
{
width: 25%;
}
/* Middle column */
.column.middle
{
width: 50%;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<div class="header">
<h1>Price Quotation</h1>
</div>
<div class="column side"></div>
<div class="column middle">
<div class="row">
<div class="col-25">
<asp:Label Text="Sales Price" runat="server"></asp:Label>
</div>
<div class="col-75">
<asp:TextBox ID="txtSalesPrice" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator runat="server" ID="rgvsalesprice" ControlToValidate="txtSalesPrice" ForeColor="Red" ErrorMessage="Please enter sale Price"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator runat="server" ID="revsaleprice" ControlToValidate="txtSalesPrice" ForeColor="Red" ValidationExpression="((d+)((.d{1,2})?))$" ErrorMessage="Please enter only number"></asp:RegularExpressionValidator>
</div>
</div>
<div class="row">
<div class="col-25">
<asp:Label ID="Label1" Text="Discount Price" runat="server"></asp:Label>
</div>
<div class="col-75">
<asp:TextBox ID="txtDiscountPercent" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator runat="server" ID="rgvdiscount" ControlToValidate="txtDiscountPercent" ForeColor="Red" ErrorMessage="Please enter discount price"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator runat="server" ID="revdiscount" ControlToValidate="txtDiscountPercent" ForeColor="Red" ValidationExpression="((d+)((.d{1,2})?))$" ErrorMessage="Please enter only number"></asp:RegularExpressionValidator>
</div>
</div>
<div class="row">
<div class="col-25">
<asp:Label ID="Label2" Text="Discount Amount" runat="server"></asp:Label>
</div>
<div class="col-75">
<asp:Label ID="lblDiscountAmount" runat="server"></asp:Label>
</div>
</div>
<div class="row">
<div class="col-25">
<asp:Label ID="Label3" Text="Total Price" runat="server"></asp:Label>
</div>
<div class="col-75">
<asp:Label ID="lblTotalPrice" runat="server"></asp:Label>
</div>
</div>
<div class="row">
<asp:Button CssClass="button" ID="btnCalculate" Text="Calculate" runat="server" />
<asp:Button CssClass="button" ID="confirmButton" runat="server" Text="Confirm" />
</div>
<div class="row">
<asp:Label ID="lblstatus" runat="server"></asp:Label>
</div>
</div>
</div>
<div class="column side"></div>
</form>
</body>
</html>
Default.ascx.cs code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication3
{
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)
{
try
{
if (IsValid)
{
decimal salesPrice = Convert.ToDecimal(txtSalesPrice.Text);
decimal discountPercent = Convert.ToDecimal(txtDiscountPercent.Text) / 100;
decimal discountAmount = salesPrice * discountPercent;
decimal totalPrice = salesPrice - discountAmount;
lblDiscountAmount.Text = discountAmount.ToString("c");
lblTotalPrice.Text = totalPrice.ToString("c");
{
Session["Price"] = txtSalesPrice.Text;
Session["Discount"] = lblDiscountAmount.Text;
Session["Total"] = lblTotalPrice.Text;
}
}
}
catch (Exception ex)
{
}
}
protected void confirmButton_Click(object sender, EventArgs e)
{
if(Session["Price"] !=null)
Response.Redirect("~/Confirm.aspx");
}
}
}
I run your code it is working find for both the pages.
Thanks,
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.