Compare
Validation for dates of format dd-MMM-yyyy in ASP.NET using C#/VB.NET
In C#:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial
class Validation4dd_MMM_yyyy
: System.Web.UI.Page
{
protected
void DatesValidator_Validate(object source, ServerValidateEventArgs
args)
{
if ((txtStartDate.Text != "")
&& (txtEndDate.Text != ""))
{
DateTime startDate = Convert.ToDateTime(txtStartDate.Text);
DateTime endDate = Convert.ToDateTime(txtEndDate.Text);
if (endDate < startDate)
{
args.IsValid =
false;
}
}
}
}
|
In VB.NET:
Imports System.Collections.Generic
Imports System.Linq
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Partial Public
Class Validation4dd_MMM_yyyy
Inherits
System.Web.UI.Page
Protected
Sub DatesValidator_Validate(ByVal source As Object, ByVal args As ServerValidateEventArgs)
If (txtStartDate.Text <> "") AndAlso
(txtEndDate.Text <> "") Then
Dim startDate As DateTime = Convert.ToDateTime(txtStartDate.Text)
Dim endDate As DateTime = Convert.ToDateTime(txtEndDate.Text)
If endDate < startDate Then
args.IsValid =
False
End If
End If
End
Sub
End Class
|
Output:
No comments:
Post a Comment