方法一:
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);
        }

 

摘自 淡蓝蓝蓝