c# - System.FormatException: String was not recognized as a valid DateTime -
i using ajax calender extender textbox, , want disable past dates, user not able select those, less today's date. code follows
in .aspx page
<asp:textbox id="txtfromdate" runat="server" ontextchanged="txtfromdate_textchanged" autopostback="true"></asp:textbox> <asp:calendarextender id="calendarextender1" runat="server" targetcontrolid="txtfromdate"> </asp:calendarextender> <asp:toolkitscriptmanager id="toolkitscriptmanager1" runat="server"> </asp:toolkitscriptmanager>
and on .cs page
protected void txtfromdate_textchanged(object sender, eventargs e) { datetime dt1 = datetime.parse(txtfromdate.text); if (dt1 < datetime.now) { //response.write("you can not choose date earlier today's date"); txtfromdate.text = null; } }
but getting following error:
system.formatexception: string not recognized valid datetime.
, there way can make date unclickable user cant choose them using startdate , enddate attributes, or other means, tried again got error these not supported. appreciated.
try if date
's format "yyyy/mm/dd":
string[] date = typeddate.text.split(new char[] { '/' }); datetime dy = new datetime(int.parse(date[0]), int.parse(date[1]), int.parse(date[2]));
Comments
Post a Comment