i have run into a problem where I have textbox with a calenderextender from ajaxtoolkit. I would like to retrieve the value the user puts in. This is how my code looks like
<asp:TextBox ID="txtValidFrom" runat="server" TextMode="DateTime" AutoPostBack="true" ></asp:TextBox>
<asp:TextBox ID="txtValidTo" runat="server"></asp:TextBox>
<ajaxToolkit:CalendarExtender ID="exValidFrom" runat="server" TargetControlID="txtValidFrom" FirstDayOfWeek="Monday" Format="dd/MM/yyyy"></ajaxToolkit:CalendarExtender>
<ajaxToolkit:CalendarExtender ID="exValidTo" runat="server" TargetControlID="txtValidTo" FirstDayOfWeek="Monday" Format="dd/MM/yyyy">
</ajaxToolkit:CalendarExtender>
And my code behind:
logg.ValidFrom = exValidFrom.SelectedDate;
logg.ValidTo = exValidTo.SelectedDate;
Where ValidFrom and ValidTo are DateTime? variables. No matter what the user presses i always get null as value. I have tried to take the text direct from the textbox using
logg.ValidFrom = System.Convert.ToDateTime(txtValidFrom.Text);
logg.ValidTo = System.Convert.ToDateTime(txtValidTo.Text);
But i get the error
String was not recognized as a valid DateTime.
Any ideas how to solve this?