ASP.NET(C#)验证数字
方法一:
int i=0;
if (!int.tryparse(this.txtpage.text, out i))
{
response.write("<script>alert('请输入有效数字!')</script>");
this.txtpage.text = string.empty;
}//判断是否是数字
方法二:
try
{
if (convert.toint32(this.txtpage.text) > totalpage || convert.toint32(this.txtpage.text)<1)
{
clientscript.registerclientscriptblock(gettype(), "提示", "alert('请输入有效数字!')", true);
}
else
{
viewstate["pageindex"] = this.txtpage.text;
getdata();
}
}
catch (exception)
{
clientscript.registerclientscriptblock(gettype(), "提示", "alert('请输入有效数字!')", true);
}
摘自 淡蓝蓝蓝
上一篇: 甩掉DataList,Repeater,列表数据显示得灵活
下一篇: asp.net之反射