代码如下:
 
protected void Page_Load(object sender, EventArgs e)
{
    if (Request.Cookies["login"] != null)
    {
     this.Button1.Attributes.Add("onclick", "if(!confirm('确实要订购吗?'))   return   false;");
    }
}
protected void Button1_Click(object sender, EventArgs e)
{
    Response.Write("<script>alert('当前购物车中,没有商品');</script>");       
    return;
}
将以上代码修改为:
 
protected void Button1_Click(object sender, EventArgs e)
{
     //Page.RegisterStartupScript("ServiceManHistoryButtonClick", "<script>alert('当前购物车中,没有商品');</script>");
     //或下面都可,上面第一个参数随便起,不要重复.
     Response.Write("<script>alert('当前购物车中,没有商品');</script>");   
     Response.Write(" <script>document.location=document.location; </script>");
     return;
}
这样就不会出现点击"取消"后出现字体变大等问题了.
第二种方式:编写一个类:
 
调用示例: