Date Format for TextMode Date RRS feed

  • Question

  • User1858009984 posted


    How to set the date format as dd/mm/yyyy for asp.net textbox with TextMode="Date"

    <asp:TextBox ID="txtDate" runat="server" TextMode="Date" ClientIDMode="Static" /><br />

    Friday, March 29, 2019 7:11 AM

All replies

  • User-1038772411 posted

    I used the Ajaxtoolkit calender, so easy and very flexible heres the code i used

    <ajaxToolkit:CalendarExtender ID="CalendarExtender1" TargetControlID="tb_search_date" Format="dd/MM/yyyy" runat="server" OnClientShown="DisableWeekends </ajaxToolkit:CalendarExtender>

    You can also try this.

    protected void Page_Load(object sender, EventArgs e)
    TextBox1.Text = DateTime.Now.ToString("dd/MM/yyyy");
    Friday, March 29, 2019 9:31 AM
  • User-2054057000 posted

    I think you are asking for Client Side solution for this rather than server side. So the client side will work instantly without page reload. 

    If you are also using jQuery Datepicker to select dates as dd/mm/yyyy then you need to add the below script to your page:

    $( "#datepicker" ).datepicker({dateFormat: "dd/mm/yyyy"});

    There is also one thread in this forum which answers the similar problem - 


    Friday, March 29, 2019 9:41 AM
  • User839733648 posted

    Hi Ravindranath M,

    According to your description, I suggest that you could use DateTime.ParseExact and ToString() to convert it on the server side as below.

    DateTime theDate=DateTime.ParseExact(textDate.Text, "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture);
    string dateToInsert=theDate.ToString("dd-MM-yyyy");

    Best Regards,


    Monday, April 1, 2019 6:19 AM
  • User-341459723 posted

    I think u can write this code in Page_Load , and don't change TextMode="Date" 

    U can use TextMode="SingleLine" 

    and write this code

    protected void Page_Load(object sender, EventArgs e)

               txtDate.Text = DateTime.Now.ToString("dd/mm/yyyy ");


    Monday, April 1, 2019 7:20 AM