#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
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
<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>
或者要把次数记录在ViewState内
基础知识:页面不保存变量i,每次刷新它都是初始值
原来如此!谢谢也就是说当点击button之后1
就重新下载也页面了!对了!哪个viewstate是什么呀!
怎么用呀1
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;
}