I have a asp:TextBox control and a javascript calendar function associated with it.
<asp:TextBox ID="txtFromDate" ReadOnly="true" runat="server" style="font-family:Verdana; font-size:11px;"></asp:TextBox>
<a href="javascript: void(0);" onmouseover="if (timeoutId) clearTimeout(timeoutId);window.status='Show Calendar';return true;" onmouseout="if (timeoutDelay) calendarTimeout();window.status='';" onclick="g_Calendar.show(event,'formAddCosting.txtFromDate',false); return false;">
<img src="Images/calendar.gif" name="calendarFromDate" width="34" border="0" alt="" /></a>
I can select the date from javascript calendar and display it in the textbox. But when I try to check the date of the textbox for validation in code behind, the dtFrom = Convert.ToDateTime(txtFromDate.Text.ToString()); shows "" during debug. How do I get the value of the textbox from code behind? I am using VB2005, ASP.Net2.0 and C#. Thanks in advance.
That is because your
TextBoxis readonly: http://www.codeproject.com/Articles/33649/ViewState-and-Readonly-Property-of-TextboxSo either enable and validate it (if user wants to enter date manually) or use a
HiddenFieldinstead to store the date from the calendar.I would recommend the first option since it’s always better not to treat the user like a child.