📄 default.aspx.cs
字号:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
this.CustomValidator1.ControlToValidate = "TextBox1";//设置要验证控件的ID
this.CustomValidator1.ErrorMessage = this.TextBox1.Text + "年不是闰年";//设置错误信息
}
protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
{
if (DateTime.IsLeapYear(Convert.ToInt32(args.Value)))//判断输入数字是否为闰年
{
args.IsValid = true;//验证通过
}
else
{
args.IsValid = false;
}
}
protected void Button1_Click(object sender, EventArgs e)
{
if (Page.IsValid == true)//判断验证是否通过
{
Response.Write(TextBox1.Text + "年是闰年");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -