I have create one application of RangeValidator Control in asp.net
Here my HTML view :
Expand|Select|Wrap|Line Numbers
- <%@ Page Language="VB" AutoEventWireup="false" CodeFile="RangeValidator_Control.aspx.vb" Inherits="RangeValidator_Control" %>
- <!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>Demo of Range Validator</title>
- </head>
- <body>
- <form id="form1" runat="server">
- <div>
- <table>
- <tr>
- <td colspan="3">
- <h2>Demo of RangeValidator</h2>
- </td>
- </tr>
- <tr>
- <td>FName</td>
- <td>
- <asp:TextBox ID="txtFname" runat="server"></asp:TextBox>
- </td>
- <td> </td>
- </tr>
- <tr>
- <td>MName</td>
- <td>
- <asp:TextBox ID="txtMname" runat="server"></asp:TextBox>
- </td>
- <td>
- <asp:RangeValidator ID="valgMname" runat="server" ErrorMessage="RangeValidator" ControlToValidate="txtMname" MaximumValue="z" MinimumValue="a">Enter valid character</asp:RangeValidator>
- </td>
- </tr>
- <tr>
- <td>Age</td>
- <td>
- <asp:TextBox ID="txtAge" runat="server"></asp:TextBox>
- </td>
- <td>
- <asp:RangeValidator ID="valgAge" runat="server" ErrorMessage="RangeValidator" ControlToValidate="txtAge" MaximumValue="25" MinimumValue="18" SetFocusOnError="true" Type="Integer">Enter age >18 and <25</asp:RangeValidator>
- </td>
- </tr>
- <tr>
- <td>Date of Next Lecture</td>
- <td>
- <asp:TextBox ID="txtDONL" runat="server"></asp:TextBox>
- </td>
- <td>(mm/dd/yy)
- <asp:RangeValidator ID="valgCal" runat="server" ErrorMessage="RangeValidator" ControlToValidate="txtDONL" SetFocusOnError="true" Type="Date" >Date should be within 5 days</asp:RangeValidator>
- </td>
- </tr>
- <tr>
- <td colspan="3">
- <asp:Button ID="btnSubmit" runat="server" Text="Submit" CausesValidation="true" />
- <asp:Button ID="btnClear" runat="server" Text="Clear" CausesValidation="false" />
- </td>
- </tr>
- </table>
- </div>
- </form>
- </body>
- </html>
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
- Partial Class RangeValidator_Control
- Inherits System.Web.UI.Page
- Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
- End Sub
- Protected Sub btnClear_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnClear.Click
- txtFname.Text = ""
- txtMname.Text = ""
- txtAge.Text = ""
- txtDONL.Text = ""
- End Sub
- Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
- If Not Page.IsPostBack Then
- valgCal.MinimumValue = CDate(Now.Date)
- valgCal.MaximumValue = CDate(Now.AddDays(5).Date)
- valgCal.Type = ValidationDataType.Date
- End If
- End Sub
- End Class
The error is as following
Error :
Expand|Select|Wrap|Line Numbers
- Server Error in '/Assignment1' Application.
- The value '25-Sep-15' of the MaximumValue property of 'valgCal' cannot be converted to type 'Date'.
- 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.
- Exception Details: System.Web.HttpException: The value '25-Sep-15' of the MaximumValue property of 'valgCal' cannot be converted to type 'Date'.
- Source Error:
- 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.
- Stack Trace:
- [HttpException (0x80004005): The value '25-Sep-15' of the MaximumValue property of 'valgCal' cannot be converted to type 'Date'.]
- System.Web.UI.WebControls.RangeValidator.ValidateValues() +1078735
- System.Web.UI.WebControls.RangeValidator.ControlPropertiesValid() +12
- System.Web.UI.WebControls.BaseValidator.get_PropertiesValid() +21
- System.Web.UI.WebControls.BaseValidator.OnPreRender(EventArgs e) +27
- System.Web.UI.Control.PreRenderRecursiveInternal() +80
- System.Web.UI.Control.PreRenderRecursiveInternal() +171
- System.Web.UI.Control.PreRenderRecursiveInternal() +171
- System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +842
- Version Information: Microsoft .NET Framework Version:2.0.50727.6387; ASP.NET Version:2.0.50727.6387
Please help me