Arane Arane - 12 days ago 5
ASP.NET (C#) Question

Grab DateTime variable from CodeBehind to javascript in ASPX

I currently have a variable called

ClassStartDate
, so this variable is a
DateTime
. I want to grab this value and pass it to
jquery datepicker
to set min date. Is there a way to do it? I tried but I can't.

Here's what I've tried

ASPX.CS

public DateTime courseStartDate;

foreach (DataRow row in retrieveBAL.retrieveBatchByProjCode(ddlProjCode.SelectedValue).Tables[0].Rows)
{
courseStartDate = Convert.ToDateTime(row["courseStartDate"]);
}


ASPX

$('#<%= tbStartDate.ClientID %>').datepicker({
dateFormat: 'dd-MM-yy',
changeMonth: true,
minDate: '<%= courseStartDate %>'
});

Answer
$('#<%= tbStartDate.ClientID %>').datepicker({
                        dateFormat: 'dd-MM-yy',
                        changeMonth: true,
                        minDate: '<%= courseStartDate.ToString("dd-MM-yy") %>'
    });
Comments