最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

vb.net - Can't retrieve date from date picker textbox in asp.net web forms formview - Stack Overflow

programmeradmin2浏览0评论

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!

发布评论

评论列表(0)

  1. 暂无评论