Change date inside TextBox with TextBoxWatermarkExtender RRS feed

  • Question

  • User1310055179 posted


    How can I change the date inside a TextBox with TextMode="Date" that uses a TextBoxWatermarkExtender?

    I can't seem to do it from code behind:

    <asp:TextBox ID="mailToDate" TextMode="Date" runat="server" Width="250px"></asp:TextBox>
                                        <ajaxToolkit:TextBoxWatermarkExtender ID="mailToDate_WM" runat="server"
                                            WatermarkCssClass="watermarked" />
    mailToDate.Enabled = true;
                    mailToDate_WM.Enabled = true;
                    mailToDate.Text = DateTime.Now.ToShortDateString();

    Monday, May 13, 2019 10:31 AM


  • User475983607 posted

    You are using two competing concepts.  The TextBox is configured to render as the HTML 5 Date input.  


    The browser controls the UI and expects a data formatted as yyyy-MM-dd not a short date string.  Change your code to set the input value to the expected format.


    I doubt the watermark extender is compatible with the HTML 5 Date input simply due to how the HTML 5 input renders in the browser.  You'll need to pick a direction.  Either use the HTML 5 input or change to a standard text input and add a JavaScript/jQuery DatePicker.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, May 13, 2019 11:14 AM