jQuery UI DatePicker Set default date as Current Date for TextBox in ASP.Net

Last Reply one year ago By dharmendr

Posted one year ago

Hello I am using datetimepicker as explained in following link

https://www.aspsnippets.com/Articles/jQuery-UI-DatePicker-Calendar-Example-in-ASPNet.aspx

I want to show current date in that textbox 1st and if user want to change the date then he can click on image button and change date as explained in above article.

Just thing I want is initialy textbox must show current date.

for that i have used following c# code on page load

txtDate.Text = DateTime.Today.ToString("MM/dd/yyyy");

This code gives current date format as - 05-09-2018

whereas my desired date format is - 05/09/2018 

How to get this desired date format ? 

Thanks

You are viewing reply posted by: nagaraju60 one year ago.
Posted one year ago

Dear @ashishk,

The problem is with your system date format. the above example gives dateformat based on your system date format. if you want your required date format then use System.Globalization. please change below query with below example 

using System.Globalization;  // add this namespace for CultureInfo.InvariantCulture


public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        txtDate.Text = DateTime.Today.ToString("MM/dd/yyyy", CultureInfo.InvariantCulture);
    }

    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        string dt = Request.Form[txtDate.UniqueID];
    }
}