方法一:
复制代码 代码如下:
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);
}