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: dharmendr one year ago.
Posted one year ago Modified on one year ago

Hi ashishk,

Check this example. Now please take its reference and correct your code.

HTML

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
<link rel="Stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" />
<script type="text/javascript">
    $(function () {
        $("[id$=txtDate]").datepicker({
            showOn: 'button'
            , buttonImageOnly: true
            , buttonImage: 'https://i.imgur.com/u6upaAs.png'
            , dateFormat: 'mm/dd/yy'
        });
        $("[id$=txtDate]").datepicker("setDate", new Date());
    });
</script>
<asp:TextBox ID="txtDate" runat="server" ReadOnly="true"></asp:TextBox>
<asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="btnSubmit_Click" />

C#

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

VB.Net

Protected Sub btnSubmit_Click(sender As Object, e As System.EventArgs)
    Dim dt As String = Request.Form(txtDate.UniqueID)
End Sub

Screenshot