Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3
This is the forum to discuss the Wrox book Beginning ASP.NET 3.5: In C# and VB by Imar Spaanjaars; ISBN: 9780470187593
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 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, 07:54 PM
Registered User
 
Join Date: Aug 2009
Posts: 7
Thanks: 2
Thanked 0 Times in 0 Posts
Default Please Help

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
{
DateTime EffDate = DateTime.MinValue;
if (DateTime.TryParseExact(dateString, "MMddyyyy", null, System.Globalization.DateTimeStyles.None, out EffDate))
{
return EffDate;
}
else
{
if (DateTime.TryParse(dateString, out EffDate))
{
return EffDate;

}
}
}
catch (Exception)
{
throw;
}

return new DateTime();
}

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
 
Old February 5th, 2010, 04:33 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

Is this related to my book Beginning ASP.NET 3.5 in C# and VB? If so, check out the discussion on page 302 and further to learn more about server- and client-side validation. Otherwise, you're better off posting these type of questions in a more generic ASP.NET 3.5 category: http://p2p.wrox.com/asp-net-3-5-436/

I also don't see any JavaScript in your code at all, so I am not sure what you're trying to accomplish. Did you mistakenly say JavaScript when you meant server side C#? Or are you trying to replicate the server check at the client as well?

Maybe you're simply not checking for IsValid in the code that's working with the data? It would help if you'd provided more infiormation and posted the relevant pieces of code.

Also, if all you're doing is "throw", then the try/catch isn't really necessary. And instead of returning new DateTime() you might as well return DateTime.MinValue as that's what you're checking against.


Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old February 5th, 2010, 09:45 AM
Registered User
 
Join Date: Aug 2009
Posts: 7
Thanks: 2
Thanked 0 Times in 0 Posts
Default

THank you verymuch for the quick reply. I am trying to replicate the check on the client side .On the code behind am doing a check for Page.IsValid .I dont know how to write the javascript for replicating this server check.
I have so many controls on the form and I want to display all the error messages on a validation summary. With my server side check, am able to validate that,but I can't display ythat error message on the validation summary.

Thank you verymusch for your help
 
Old February 5th, 2010, 09:56 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Quote:
I dont know how to write the javascript for replicating this server check.
Check out the CompareValidator on page 298. It shows how to set up a validator to validate dates.
Quote:
but I can't display ythat error message on the validation summary
This should work automatically. If one of the controls is not valid and the ValidationSummary is setup correctly, it displays the errors automatically. Check out page 302 and onward for more instructions.

If that doesn't help, you need to post the relevant bits of your code.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!









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