如何统计button被点击的次数
1个回答
展开全部
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
public static int number = 0;
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
number = 0;
}
}
protected void Button1_Click(object sender, EventArgs e)
{
if (number < 3)
{
if ( TextBox1.Text.ToString().Trim() == "admin")
{
Response.Write("您已经成功登录!");
}
else
{
number += 1;
}
}
else
{
Response.Write("您登录失败的次数太多,不能在登录了!");
}
}
}
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!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">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server" Text="请输入用户名!"></asp:TextBox>
<br />
<asp:TextBox ID="TextBox2" runat="server" Text="请输入密码!"></asp:TextBox>
<br />
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
</div>
</form>
</body>
</html>
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
public static int number = 0;
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
number = 0;
}
}
protected void Button1_Click(object sender, EventArgs e)
{
if (number < 3)
{
if ( TextBox1.Text.ToString().Trim() == "admin")
{
Response.Write("您已经成功登录!");
}
else
{
number += 1;
}
}
else
{
Response.Write("您登录失败的次数太多,不能在登录了!");
}
}
}
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!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">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server" Text="请输入用户名!"></asp:TextBox>
<br />
<asp:TextBox ID="TextBox2" runat="server" Text="请输入密码!"></asp:TextBox>
<br />
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
</div>
</form>
</body>
</html>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询