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