By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,091 Members | 1,555 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,091 IT Pros & Developers. It's quick & easy.

Need help to solve the error

Ajay Bhalala
100+
P: 119
Hello all,

I have create one application of RangeValidator Control in asp.net

Here my HTML view :
Expand|Select|Wrap|Line Numbers
  1. <%@ Page Language="VB" AutoEventWireup="false" CodeFile="RangeValidator_Control.aspx.vb" Inherits="RangeValidator_Control" %>
  2.  
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  4.  
  5. <html xmlns="http://www.w3.org/1999/xhtml">
  6. <head runat="server">
  7.     <title>Demo of Range Validator</title>
  8. </head>
  9. <body>
  10.     <form id="form1" runat="server">
  11.     <div>
  12.         <table>
  13.             <tr>
  14.                 <td colspan="3">
  15.                     <h2>Demo of RangeValidator</h2>
  16.                 </td>
  17.             </tr>
  18.  
  19.             <tr>
  20.                 <td>FName</td>
  21.  
  22.                 <td>
  23.                     <asp:TextBox ID="txtFname" runat="server"></asp:TextBox>
  24.                 </td>
  25.  
  26.                 <td>&nbsp;</td>
  27.             </tr>
  28.  
  29.             <tr>
  30.                 <td>MName</td>
  31.  
  32.                 <td>
  33.                     <asp:TextBox ID="txtMname" runat="server"></asp:TextBox>
  34.                 </td>
  35.  
  36.                 <td>
  37.                     <asp:RangeValidator ID="valgMname" runat="server" ErrorMessage="RangeValidator" ControlToValidate="txtMname" MaximumValue="z" MinimumValue="a">Enter valid character</asp:RangeValidator>
  38.                 </td>
  39.             </tr>
  40.  
  41.             <tr>
  42.                 <td>Age</td>
  43.  
  44.                 <td>
  45.                     <asp:TextBox ID="txtAge" runat="server"></asp:TextBox>
  46.                 </td>
  47.  
  48.                 <td>
  49.                     <asp:RangeValidator ID="valgAge" runat="server" ErrorMessage="RangeValidator" ControlToValidate="txtAge" MaximumValue="25" MinimumValue="18" SetFocusOnError="true" Type="Integer">Enter age &gt;18 and &lt;25</asp:RangeValidator>
  50.                 </td>
  51.             </tr>
  52.  
  53.             <tr>
  54.                 <td>Date of Next Lecture</td>
  55.  
  56.                 <td>
  57.                     <asp:TextBox ID="txtDONL" runat="server"></asp:TextBox>
  58.                 </td>
  59.  
  60.                 <td>(mm/dd/yy)
  61.                     <asp:RangeValidator ID="valgCal" runat="server" ErrorMessage="RangeValidator" ControlToValidate="txtDONL" SetFocusOnError="true" Type="Date" >Date should be within 5 days</asp:RangeValidator>
  62.                 </td>
  63.             </tr>
  64.  
  65.             <tr>
  66.                 <td colspan="3">
  67.                     <asp:Button ID="btnSubmit" runat="server" Text="Submit" CausesValidation="true" />
  68.                     <asp:Button ID="btnClear" runat="server" Text="Clear" CausesValidation="false" />
  69.                 </td>
  70.             </tr>
  71.         </table>
  72.     </div>
  73.     </form>
  74. </body>
  75. </html>
  76.  

Here is my Design View

Demo of RangeValidator
FName txtFname
MName txtMname Enter valid character
Age txtAge Enter age >18 and <25
Date of Next Lecture txtDONL (mm/dd/yy)Date should be within 5 days

btnSubmit btnClear


Here is the Coding View
Expand|Select|Wrap|Line Numbers
  1. Partial Class RangeValidator_Control
  2.     Inherits System.Web.UI.Page
  3.  
  4.     Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
  5.  
  6.     End Sub
  7.  
  8.     Protected Sub btnClear_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnClear.Click
  9.         txtFname.Text = ""
  10.         txtMname.Text = ""
  11.         txtAge.Text = ""
  12.         txtDONL.Text = ""
  13.     End Sub
  14.  
  15.     Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  16.         If Not Page.IsPostBack Then
  17.             valgCal.MinimumValue = CDate(Now.Date)
  18.             valgCal.MaximumValue = CDate(Now.AddDays(5).Date)
  19.             valgCal.Type = ValidationDataType.Date
  20.         End If
  21.     End Sub
  22. End Class
  23.  
I have write as above in different views, but there is an error occured.

The error is as following
Error :
Expand|Select|Wrap|Line Numbers
  1. Server Error in '/Assignment1' Application.
  2.  
  3. The value '25-Sep-15' of the MaximumValue property of 'valgCal' cannot be converted to type 'Date'.
  4.  
  5. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
  6.  
  7. Exception Details: System.Web.HttpException: The value '25-Sep-15' of the MaximumValue property of 'valgCal' cannot be converted to type 'Date'.
  8.  
  9. Source Error: 
  10.  
  11. An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
  12.  
  13. Stack Trace: 
  14.  
  15.  
  16. [HttpException (0x80004005): The value '25-Sep-15' of the MaximumValue property of 'valgCal' cannot be converted to type 'Date'.]
  17.    System.Web.UI.WebControls.RangeValidator.ValidateValues() +1078735
  18.    System.Web.UI.WebControls.RangeValidator.ControlPropertiesValid() +12
  19.    System.Web.UI.WebControls.BaseValidator.get_PropertiesValid() +21
  20.    System.Web.UI.WebControls.BaseValidator.OnPreRender(EventArgs e) +27
  21.    System.Web.UI.Control.PreRenderRecursiveInternal() +80
  22.    System.Web.UI.Control.PreRenderRecursiveInternal() +171
  23.    System.Web.UI.Control.PreRenderRecursiveInternal() +171
  24.    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +842
  25.  
  26. Version Information: Microsoft .NET Framework Version:2.0.50727.6387; ASP.NET Version:2.0.50727.6387   
  27.  
Please help me to solve this error. Which changes I have to do in my code????

Please help me
Sep 20 '15 #1
Share this Question
Share on Google+
1 Reply


Ajay Bhalala
100+
P: 119
Please anyone suggest me how to solve this error!!!
Sep 28 '15 #2

Post your reply

Sign in to post your reply or Sign up for a free account.