Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I validate the date is not the future date in .net c#
    text
    copied!<p>Just wandering, how can I validate the date is not the future date in .net c#.</p> <p>Example:</p> <p>I have applied a validation there for required field validation. But somehow I have no idea how to apply the validation to check the start date to make sure it's not the future date (date not greater then the current date)?</p> <pre><code> &lt;tr&gt; &lt;td align="right"&gt;Start Date:&lt;/td&gt; &lt;td&gt;&lt;asp:TextBox runat="server" ID="activeDate" size="8"/&gt;(YYYY-MM-DD) &lt;asp:RequiredFieldValidator ID="reqvactiveDate" runat="server" ControlToValidate="activeDate" Display="Dynamic" EnableClientScript="true" ErrorMessage="required" /&gt; &lt;/td&gt; &lt;/tr&gt; </code></pre> <p>than I wrote the following code to tried out the date validation. The date validation doesn't seem working for me :(</p> <pre><code> &lt;tr&gt; &lt;td align="right"&gt;Start Date:&lt;/td&gt; &lt;td&gt;&lt;asp:TextBox runat="server" ID="activeDate" size="8"/&gt;(YYYY-MM-DD) &lt;asp:RequiredFieldValidator ID="reqvactiveDate" runat="server" ControlToValidate="activeDate" Display="Dynamic" EnableClientScript="true" ErrorMessage="required" /&gt; &lt;asp:CustomValidator runat="server" ID="valDateRange" ControlToValidate="activeDate" onservervalidate="valDateRange_ServerValidate" ErrorMessage="enter valid date" /&gt; &lt;/td&gt; &lt;/tr&gt; </code></pre> <p>code behind:</p> <pre><code> protected void valDateRange_ServerValidate(object source, ServerValidateEventArgs args) { DateTime minDate = DateTime.Parse("1000/12/28"); DateTime maxDate = DateTime.Parse("2011/05/26"); DateTime dt; args.IsValid = (DateTime.TryParse(args.Value, out dt) &amp;&amp; dt &lt;= maxDate &amp;&amp; dt &gt;= minDate); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload