Wrox Programmer Forums
|
BOOK: Professional ASP.NET 3.5 : in C# and VB ISBN: 978-0-470-18757-9
This is the forum to discuss the Wrox book Professional ASP.NET 3.5: In C# and VB by Bill Evjen, Scott Hanselman, Devin Rader; ISBN: 9780470187579
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional ASP.NET 3.5 : in C# and VB ISBN: 978-0-470-18757-9 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 4th, 2010, 12:44 AM
Registered User
 
Join Date: Aug 2009
Posts: 7
Thanks: 2
Thanked 0 Times in 0 Posts
Default Using Custom validator and Validation summary

Hi ..I have an aspx page with lot of controle on it. I am using a custom validator control (with the serverside validation). Is there a way to display the error message on the validation summary without writing Javasccript. I am a beginner in .NET and am not fluent in Javascript.
This is the custom validator HTML


<asp:CustomValidator ID="CustomValidator1" runat="server" ErrorMessage="Invalid Date"
ControlToValidate="txtDate" OnServerValidate="ValidateDate_ServerValidate" ValidationGroup="vgSetUp"
></asp:CustomValidator>



This is the utility method am trying to validate for the entry on the UI, so that it takes dates only in these formats
MMDDYYYY,MM/DD/YYYY,MM/DD/YY,MM-DD-YY,MM-DD-YYYY,YYYY-MM-DD
If the user enters date in any other format, this method returns returns the Datetime.Mivalue(1/1/0001)

public DateTime GetFomattedDate(string dateString)
{
try
{
string[] formats = {
"MMddyyyy", // These are the accepted date formats for the UI
"MM/dd/yyyy",
"M/d/yyyy",
"yyyy/MM/dd",
"yyyy/M/d"
};

DateTime EffDate = DateTime.MinValue;
if ( DateTime.TryParseExact(dateString,formats, null, System.Globalization.DateTimeStyles.None, out EffDate))
{
return EffDate;
}

}
catch (Exception)
{
throw;
}

return DateTime.MinValue;
}

This is my customvalidator event handler(code behind)

protected void ValidateDate_ServerValidate(object source,servervalidate eventargs args)

{
args.IsValid = GetFomattedDate(args.Value) ==DateTime.MinValue? false:true;

}

I am able to validate it properly, but I cannot display the error message in the validation summary along with other messages.
Anyone who is expert on Javascript can Help with the javascript function?

Any help would be greatly appreciated
Thanks
Rennish

Last edited by rennishj; February 9th, 2010 at 05:29 PM..





Similar Threads
Thread Thread Starter Forum Replies Last Post
DDL Custom Validator AspNetGuy BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 2 June 6th, 2008 05:17 PM
validation summary MunishBhatia ASP.NET 2.0 Professional 1 May 11th, 2007 08:00 AM
Message Box for Validation Summary diptidjadhav ASP.NET 1.0 and 1.1 Basics 0 April 3rd, 2006 05:15 AM
custom validator question kscdave Classic ASP Professional 3 April 24th, 2005 07:11 AM
Custom Validator bmains ASP.NET 1.0 and 1.1 Basics 4 December 18th, 2003 11:45 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.