.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

How to validate dates?

Posted By:      Posted Date: October 01, 2010    Points: 0   Category :ASP.Net

I need to validate a date entered in a textfield (but is a DateTime anyway) and display the error to the user if there's some problem, like an invalid date (p.e. 31st of February should return an error).

If I do insert an invalid date, I get a

Cannot convert value of parameter 'DataNascimento' from 'System.String' to 'System.DateTime'.

as expected, but I don't want to display this message to the user.

Is there a way to catch this exception and change the display text?
Or to make the check before and show the error to the user inline?

I already tried the OnXXXXChanging method, but the exception is thrown before that method is called.

View Complete Post

More Related Resource Links

JQuery Validate plugin to validate a ASP.NET Form

The first time I used the JQuery Validate plugin, it did not work at all, see JQuery Validate odd behaviour with the ASP.NET Script Manager for reason, but perseverance and stubbornness prevailed and I finally created my first JQuery validated ASP.NET Forms contact form.

Validate form input - Japanese


 I've searched for several hours and haven't come up with a reference - or even many discussions - of how to go about validating Japanese names, addresses, etc. When I lived in Japan websites, atm's etc. required such info to be entered with the roman alphabet but I've seen some websites that are allowing Kanji/Hiragana/Katakana. I haven't tested many of them for validation but one that I did test (after looking at the page source and discovering no client-side validation) allowed me to put this in the name field: J*=123*go^ Neat!

Any pointers/references? Thanks

Need function to find difference between two dates


Hi all

I need a function written in vb to find the exact month difference between two dates.

For example

    Start Date : 01/01/2010

    End Date   : 15/02/2010

 then the difference value should be like this 1.5  i.e i need the difference in decimal value.

Validate mutually exclusive text boxes


Meaning only one of them can have a value, but not both.

I suspect one validation control can't handle both.


Any ideas? 

validate the selection of atleast one checkbox in the gridview using javascript


 i have a gridview with a checkbox in the templatefield as given  below,

<asp:GridView runat="server" ID="gvAsgnHw"  AutoGenerateColumns="False"   >
        <asp:CheckBox id="cbAsgnHwGrid"   runat="server" /> </ItemTemplate></asp:TemplateField>

         <asp:BoundField DataField="Resource_id" HeaderText="Resource ID"/>
        <asp:BoundField DataField="Resource_name" HeaderText="Hardware Name" />

I want to check the selection of atleast one checkbox on a button click using javascript.
pls help

How to increment default dates in the subscription


I have a report that I want run on a monthly subscription, but the report has a default date parameter. Is there a way to have the default date parameter increment each month. So if I choose to receive the subscription monthly I would want that default date to increment.

Unable to validate data


Hi All,

Thank you for advance.

I created the web application using asp.net 2.0, c# and sql server 2005

sometimes i am getting the following error,

Message: Unable to validate data.

Source: System.Web

TargetSite: Byte[] GetDecodedData(Byte[], Byte[], Int32, Int32, Int32 ByRef)

StackTrace:    at System.Web.Configuration.MachineKeySection.GetDecodedData(Byte[] buf, Byte[] modifier, Int32 start, Int32 length, Int32& dataLength)
   at System.Web.UI.ObjectStateFormatter.Deserialize(String inputString)

Problem in Custom Control Unable to find Control To Validate Property


I make a custome control by taking a TextBox and A Regular Expression Validator.When i Use this on a .aspx page it works fine.But when i use this on .ascx page and dynamically load user control on a place holder in .aspx page it through an Error

Unable to find control id '_ctl0:txtEmail' referenced by the 'ControlToValidate' property of '_ctl0:txtEmailRequired'


My Custome control Code is this"--

public class EmailValidator:System.Web.UI.Control, INamingContainer{

private System.Web.UI.WebControls.TextBox textBox;

private System.Web.UI.WebControls.RegularExpressionValidator regularExpressionValidator;

public EmailValidator(){

textBox = new TextBox();

regularExpressionValidator = new RegularExpressionValidator();

IsErrorTextBelow = true;

IsRequired = false;

Get Dates from Sunday thru Saturday


I'm using the date picker and I need to know how (or if it's even possible), to select a date, and based on the date, have the actual query use the week the date was in and return all the records from that week (Sunday through Saturday)

Like - if I pick 8/24/2010 - it returns a date range of 8/22 through 8/28
I'd also like to display the date range in the report, somehow

Any ideas on how I do this?

i need a good function that will validate an email adress

i need a function that will check whether a string input is a valid email adress or not thnx a lot

how do i create a windows form application login for to validate username and password from sql serv

 I would like to know how I can create a login form for my windows form application. The login form must be linked to a SQL server 2005 express edition database (in which the username and passwords are stored). The login form must validate the user using the database and allow them to access the program. 

QUERY filter dates by DAY

i have the following data : first column: dates and 2nd column: values i want to filter the dates per day and calculate the AVERAGE of their values per day i can filter them manually by setting day(datetimefield) = 12 and calculate the AVERGAE but i dont know how to do it for all in one query? each record resulting the average of that day   2010-07-12 00:00:00.000 900 2010-07-12 10:00:00.000 1000 2010-07-12 10:10:00.000 1200 2010-07-12 12:00:00.000 1100 2010-07-12 15:00:00.000 1300 2010-07-12 15:10:00.000 1500 2010-07-13 00:00:00.000 6500 2010-07-13 10:00:00.000 5500 2010-07-14 00:00:00.000 5500 2010-07-14 10:00:00.000 4400 2010-07-15 10:00:00.000 4500 2010-07-16 00:00:00.000 1000 2010-07-17 00:00:00.000 7000 2010-07-18 00:00:00.000 8500 2010-07-19 00:00:00.000 1500 2010-07-20 00:00:00.000 1700 2010-07-21 00:00:00.000 1900 2010-07-22 00:00:00.000 2000  

Hiding other month dates in ASP .Net Calendar Control

Often we need ASP .Net calendar control in our webpages. Most of the times we require navigation in between dates of the calendar control but there can be a requirement that when we want that users should not be able to select dates from month other than the current month.Some people might be thinking in mind that Microsoft has provided theShowNextPrevMonth property of a calendar control which can be set to false in order to disable the navigation in between months. Ok, this will disable navigation but what about the dates of adjacent months shown in current month?Following is the output of a normal Calendar control when ShowNextPrevMonth is not set to false.Note the red circles in above image. July and September will allow you to navigate through other months and red circles below will allow you to select dates of adjacent months.Ok now we set the ShowNextPrevMonth property to false and see the output. Following is the output in this case.So setting out the ShowNextPrevMonth property has disabled the July and Septemberlinks but dates of adjacent months are still there which can be selected as well. How to disable/hide these? Unfortunately there is no such default property provided using which one can disable or hide these dates but fortunately doing this using code is not a complex task. Use following code a

validate data

Hi, i have a xsd schema and i have to validate records taken from a csv file, i am using a datatable associating it with the schema but i don't now how see if the data is in the wright format because from csv i take a string. Can anyone explain what to do, thanks.

passing dates in stored procedure?

I am trying to pass dates in  a stored procedure and keep getting an error - here is the code and error.  eventually the sproc will be used in SSRS.     ALTER PROC [dbo].[USP_SPROC_X] @DATE DATETIME AS SELECT ITEM , PRICE , SELL_DSCR , PRC_EFF_DT , PRC_END_DT , PROPOSED_BY ,CONFIRMED_BY FROM SALES WHERE @DATE BETWEEN PRC_EFF_DT AND PRC_END_DT   Msg 4104, Level 16, State 1, Procedure [PROCNAME], Line 141 The multi-part identifier "PRC_EFF_DT" could not be bound.

validate and hidden fields

Here is my dilemma, I have a web page that I hides and shows textboxes based off a selection within a dropdown. The dropdown shows Yes/No, if they select NO they see one set of textboxes to fill out, if they select YES they see a different set of textboxes, once they're done, they click submit which does validation. Here is my issue. ALL textboxes are required, so how can I not validate the textboxes that are not showing on the screen? I'm hiding them like this: var show=""; function show(o) { if (show != "") show.style.display = 'none'; if(o.selectedIndex>0) { var d=document.getElementById(o[o.selectedIndex].value); d.style.display='block'; show = d; } } and I call that from my dropdown. onchange="show(this);">   and I have this in my HTML <tbody id="N1" style="display: none;"> </tbody> and I have textboxes within the N1 tag, I also have an N2 tag that shows if YES is selected.each tag has required textboxes, how can I not validate the textboxes if they are not showing on the screen and are in the hidden N tag?  

how to validate xml with xml schema

I am trying to validate xml file wth the xml schema and if there is no violation then I would like to write the xml file to the dataset and save it to the database. my problem here is that if i have more than one error it does not show up. the first violation is the only one that displays in the error messge. can someone help me to fix my code below     ImportsSystem.IO ImportsSystem.Xml ImportsSystem.Data ImportsSystem.Xml.Schema ImportsSystem.Collections ImportsSystem.Data.OracleClient ImportsSystem.Configuration.ConfigurationManager Partial    Class PyrollInherits System.Web.UI.PageDim XMLPath As String  Dim XSDPath As String          Dim Reader As XmlTextReaderDim ErrResult As New ArrayList()Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.ClickIf (FileUpload1.HasFile) Then XSDPath = "F:\XSDFile\address.xsd" ValidatingProcess()  Else lblError.Text = "Please upload a valid xml file"  End If    End Sub   ValidatingProcess()    Public Function ValidateIt() As ArrayListReturn Me.ErrResultEnd Function  Private Function ValidatingProcess() As Boolean       Reader =      Dim ds As DataSet = New DataSetDim readFile As StreamReader = New StreamReader(FileUpload1.PostedFile.InputS
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend