I'm working with an ASP.NET Web Forms application using VB.NET. In my FormView's EditTemplate, I have a TextBox that is set up as a date picker using TextMode="Date". The TextBox is bound to a date field and formatted using a binding expression:
<asp:TextBox
ID="txtStartDateEdit"
TextMode="Date"
runat="server"
CssClass="form-control form-control-sm"
Text='<%# Bind("startDate", "{0:yyyy-MM-dd}") %>'
Enabled="true" />
In the code-behind, I try to retrieve the selected date when a button is clicked:
Protected Sub btnSaveCore_Click(sender As Object, e As EventArgs)
Dim txtStartDate As TextBox = CType(frmOpportunity.Row.FindControl("txtStartDateEdit"), TextBox)
Dim txtEndDate As TextBox = CType(frmOpportunity.Row.FindControl("txtEndDateEdit"), TextBox)
Dim SelectedStartDate As DateTime = DateTime.Parse(txtStartDate.Text)
Dim SelectedEndDate As DateTime = DateTime.Parse(txtEndDate.Text)
' Code to update stored procedure etc.
End Sub
When the TextMode is set to "Date", the Text property (e.g., txtStartDate.Text) comes back empty or null. However, if I switch the TextBox to a standard mode (without TextMode="Date"), the value is retrieved correctly and the update stored procedure works as expected.
How can I retrieve the selected date value from the TextBox when TextMode is set to "Date"? Is there something special about using the HTML5 date picker that I need to handle differently in my code-behind?
Any insights or workarounds would be appreciated. Thanks!