admin管理员组文章数量:1319461
I have a asp:textbox , how can i set its minimum date to today using javascript:
With C# I am doing it like this and it works fine..but I have to do it using Js/Jquery
DateTime date = DateTime.Today.Date;
String today = date.ToString("yyyy-MM-dd");
tourStartDate.Attributes["min"] =today;
<asp:TextBox Width="95%" ID="tourStartDate" runat="server" TextMode="Date" onchange="SetDate()"></asp:TextBox></td>
I have a asp:textbox , how can i set its minimum date to today using javascript:
With C# I am doing it like this and it works fine..but I have to do it using Js/Jquery
DateTime date = DateTime.Today.Date;
String today = date.ToString("yyyy-MM-dd");
tourStartDate.Attributes["min"] =today;
<asp:TextBox Width="95%" ID="tourStartDate" runat="server" TextMode="Date" onchange="SetDate()"></asp:TextBox></td>
Share
Improve this question
asked Jun 29, 2015 at 5:30
Syed Muhammad YasirSyed Muhammad Yasir
1054 silver badges14 bronze badges
4
- possible duplicate of Minimum and maximum date – Shirish Commented Jun 29, 2015 at 6:01
- Can you show the SetDate() method ? – sudhansu63 Commented Jul 1, 2015 at 7:39
- function SetDate() { if (document.getElementById('<%=tourEndDate.ClientID%>').value <= document.getElementById('<%=tourStartDate.ClientID%>').value) { $('#<%=tourEndDate.ClientID %>').val(document.getElementById('<%=tourStartDate.ClientID%>').value); } – Syed Muhammad Yasir Commented Jul 1, 2015 at 8:43
- @SyedMuhammadYasir Please add the content of your ment to your question. After that delete your ment. – Reporter Commented Feb 15, 2017 at 13:30
4 Answers
Reset to default 3On Code Behind C#:
tourStartDate.Attributes["max"] = DateTime.Now.ToString("yyyy-MM-dd");
VB:
tourStartDate.Attributes("max") = Now.ToString("yyyy-MM-dd")
you need to put the ClientIdMode = static
in the server control to get the static Id.
<asp:TextBox Width="95%" ID="tourStartDate" ClientIdMode = "static" runat="server" TextMode="Date" onchange="SetDate()"></asp:TextBox>
Jquery: Set today in attribute.
$("#tourStartDate").attr("min", (new Date()));
EDIT:
Can you try <input type="date" min="2015-07-01" max="2015-10-20">
JQuery:
$("#tourStartDate").attr("min", (new Date()).toISOString().substring(0,10));
Make sure your doc type is html ( for HTML 5 controls)
EDIT2 :
JavaScript :
document.getElementById('tourStartDate').setAttribute('min', (new Date()).toISOString().substring(0,10));
My design code is :
<asp:TextBox ID="txtDate" runat="server" MaxLength="30" CssClass="form-control" autoplete="off"></asp:TextBox>
Javascript code and jquery code
$(function () {
$("#ContentPlaceHolder1_txtDate").datepicker({
minDate: new Date(new Date().getTime() - 2 * 24 * 60 * 60 * 1000),
maxDate: new Date()
});
});
Although not a javascript/jQuery solution, this is another ASP.NET flavor. Use the OnInit to set the attributes.
ASPX:
<asp:TextBox ID="calEnd" runat="server" CssClass="datefield" data-val="true" OnInit="cal_Init" data-val-required="End date is required" type="date" />
Code Behind:
protected void cal_Init(object sender, EventArgs e)
{
var inp = (TextBox)sender;
inp.Attributes.Add("min", (DateTime.Now.Year - 10).ToString() + "-01-01");
inp.Attributes.Add("max", (DateTime.Now.Year + 2).ToString() + "-12-31");
}
本文标签: How to set minimum and maximum date of asptextbox textmodedateusing javascriptjqueryStack Overflow
版权声明:本文标题:How to set minimum and maximum date of asp:textbox textmode=date ??? using javascriptjquery - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742061706a2418619.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论