#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{    
///////////////////////////////////
this.Button1.Click += new System.EventHandler(Button1_Click);
                  ////////////////////////////////////////应该是少了这个 this.Load += new System.EventHandler(this.Page_Load); }
#endregion

解决方案 »

  1.   

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="gb2312" lang="gb2312">
    <head>
    <title> New Document </title>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <meta name="title" content="" />
    <meta name="author" content="活靶子,Huobazi,www.AspxBoy.com" />
    <meta name="subject" content="" />
    <meta name="language" content="gb2312" />
    <meta name="keywords" content="" />
    <meta name="Copyright" content="www.AspxBoy.com" />
    <meta name="robots" content="all" />
    <script language="c#" runat="server">
    static int i;
    void clickbutton(object o,EventArgs e)
    {
    i++;
    Response.Write("您点击了"+i.ToString()+"次");
    }
    </script>
    </head>
    <body>
    <form runat="server" id="frm">
    <asp:button id="btn" runat="server" onclick="clickbutton" Text="Click" />
    </form></body>
    </html>
      

  2.   

    如果你的i定义的不是static变量那么页面每次回发后都又初始化了
    或者要把次数记录在ViewState内
      

  3.   

    刚开始学asp.net  .....
    基础知识:页面不保存变量i,每次刷新它都是初始值
      

  4.   

    噢!
    原来如此!谢谢也就是说当点击button之后1
    就重新下载也页面了!对了!哪个viewstate是什么呀!
    怎么用呀1
      

  5.   

    viewstate这样用
    private void Button1_Click(object sender, System.EventArgs e)
    {
        int i=0;
        if(this.ViewState["test"] != null)
            i= (int)ViewState["test"];    i++;
        this.Label1.Text ="^_^,你已经点击了"+this.i.ToString()+"次";
        this.Button1.Text = "^_^,你已经点击了"+this.i.ToString()+"次";

        ViewState["test"] = i;  
    }