下面提到的代码用于验证未来的日期,但它不起作用。任何帮助都会受到重视。文本框已将只读属性设置为 false,因此我可以更改文本框中的值并更改为未来日期,对于该条件我需要验证
// 在 aspx 中
<asp:TextBox ID="txtdob" runat="server" OnClientDateSelectionChanged="checkDate"></asp:TextBox>
<asp:Button ID="Button2" runat="server" onclick="Button2_Click" Height="26px" Width="23px" Text=".." />
<script type="text/javascript" >
function checkDate(sender, args)
{
if (sender._selectedDate > new Date())
{
alert("You cannot select future date!");
sender._selectedDate = new Date();
// set the date back to the current date
sender._txtdob.set_Value(sender._selectedDate.format(sender._format))
}
}
</script>
<asp:Calendar ID="Calendar1" runat="server" onselectionchanged="Calendar1_SelectionChanged" OnClientDateSelectionChanged="checkDate"
style="top: 320px; left: 246px; position: absolute; height: 188px; width: 259px">
</asp:Calendar>
//在c#中
protected void Button2_Click(object sender, EventArgs e)
{
Calendar1.Visible = true;
}
protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{
txtdob.Text = Calendar1.SelectedDate.ToShortDateString();
}