I'm trying to do a click counter in ASP.NET webforms and C #, and I need to convert the% number of clicks to a string in the label . But this does not work, the page is displayed but the number of clicks (the label ) does not appear.
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Teste
{
public partial class WebForm2 : System.Web.UI.Page
{
int clicks = 0;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btn_Click(object sender, EventArgs e)
{
clicks++;
Label1.Text = clicks.ToString();
}
}
}
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs" Inherits="Teste.WebForm2" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Clickount</title>
<link rel="stylesheet" href="bootstrap.css" />
</head>
<body>
<form runat="server">
<center>
<h1>Click counter</h1>
<asp:Label ID="Label1" runat="server" Text=""></asp:Label>
<br />
<asp:Button ID="btn" runat="server" Text="Add" CssClass="btn btn-primary"></asp:Button>
</form>
</body>
</html>
The only thing you do not do is display the number of clicks, the rest appears.