当前位置:编程学习 > asp >>

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);
        }

 


摘自 淡蓝蓝蓝

补充:Web开发 , ASP.Net ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,