|
-
Oct 10th, 2007, 01:47 AM
#1
Thread Starter
Member
[RESOLVED] asp .net 2.0 range validation controls
I am trying to complete a project at the end of chapter 2 in a "Murach" book. It is "ASP .NET 2.0 for Visual Basic 2005. Anyway, the project is a future value calculator that calculates the future value on a monthly investment for a specified amount of years.
The range validation controls are not working like they are supposed to. The program is supposed to make the user enter a interest rate between 1-20. So any number between 1-20 and the user is supposed to specify how many years they want to calculate the investment, but both of these validation controls won't allow just any number that I set that is between the minimum and maximum properties that I have set.
Here is a image that will help you see what my program looks like.

Here is the code in the aspx file:
Code:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Future Value</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<img src="Images/MurachLogo.jpg" alt="Murach" /><br />
<br />
<span style="font-size: 24pt"><strong>401K Future Value Calculator</strong></span><br />
<br />
<table>
<tr>
<td width="149">
Monthly investment</td>
<td width="71">
<asp:DropDownList ID="ddlMonthlyInvestment" runat="server" Width="106px">
</asp:DropDownList></td>
</tr>
<tr>
<td width="149">
Annual interest rate</td>
<td width="71">
<asp:TextBox ID="txtInterestRate" runat="server" CausesValidation="True"></asp:TextBox></td>
</tr>
<tr>
<td width="149">
Number of years</td>
<td width="71">
<asp:TextBox ID="txtYears" runat="server" CausesValidation="True"></asp:TextBox></td>
</tr>
<tr>
<td width="149">
Future value</td>
<td width="71">
<asp:Label ID="lblFutureValue" runat="server" Width="152px"></asp:Label></td>
</tr>
<tr>
<td width="149">
</td>
<td width="71">
</td>
</tr>
<tr>
<td style="height: 21px" width="149">
<asp:Button ID="btnCalculate" runat="server" Text="Calculate" Width="94px" /></td>
<td style="height: 21px" width="71">
<asp:Button ID="btnClear" runat="server" Text="Clear" Width="100px" CausesValidation="False" /></td>
</tr>
</table>
<br />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtInterestRate"
Display="Dynamic" ErrorMessage="Interest rate is required." SetFocusOnError="True"></asp:RequiredFieldValidator><br />
<asp:RangeValidator ID="RangeValidator1" runat="server" ControlToValidate="txtInterestRate"
Display="Dynamic" ErrorMessage="Interest rate must range from 1 to 20." MaximumValue="20"
MinimumValue="1" SetFocusOnError="True"></asp:RangeValidator><br />
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="txtYears"
Display="Dynamic" ErrorMessage="Number of years is required." SetFocusOnError="True"></asp:RequiredFieldValidator><br />
<asp:RangeValidator ID="RangeValidator2" runat="server" ControlToValidate="txtYears"
Display="Dynamic" ErrorMessage="Years must range from 1 to 45." MaximumValue="45"
MinimumValue="1" SetFocusOnError="True"></asp:RangeValidator></div>
</form>
</body>
</html>
Here is just the code for the validation controls so you won't have to look at all the code.
Code:
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtInterestRate"
Display="Dynamic" ErrorMessage="Interest rate is required." SetFocusOnError="True"></asp:RequiredFieldValidator><br />
<asp:RangeValidator ID="RangeValidator1" runat="server" ControlToValidate="txtInterestRate"
Display="Dynamic" ErrorMessage="Interest rate must range from 1 to 20." MaximumValue="20"
MinimumValue="1" SetFocusOnError="True"></asp:RangeValidator><br />
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="txtYears"
Display="Dynamic" ErrorMessage="Number of years is required." SetFocusOnError="True"></asp:RequiredFieldValidator><br />
<asp:RangeValidator ID="RangeValidator2" runat="server" ControlToValidate="txtYears"
Display="Dynamic" ErrorMessage="Years must range from 1 to 45." MaximumValue="45"
MinimumValue="1" SetFocusOnError="True"></asp:RangeValidator></div>
As you can see the minimum and maximum values are set correctly, but for some reason, I can not enter {3,4,5,6,7,8,9} in the annual interest text box.
Some of the numbers below 10 works for the years text box, but some don't. All numbers that I set that is between the minimum and maximum values that I set in the properties windows should be allowed and should not tell the program that the number in the text property of the text box is invalid, when the number is valid and is between the minimum and maximum values that have been set in both of the range validation controls.
Hopefully, someone can figure this out. I am using "Visual Web Developer 2005" with .NET 2.0 installed.
Last edited by kevin_10987; Oct 10th, 2007 at 02:56 AM.
Reason: to change title
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|