2
I’m trying to do a click counter in ASP.NET webforms and c#, and I need to convert the number int
click-through to a string in label. Only this does not work, the page is displayed but the number of clicks (a 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 it doesn’t do is display the one of clicks, the rest appears.
Try changing the line that puts value on
label
forLabel1.Text = "clicks aqui";
to see if the problem is the same conversion.– Maniero
@Moustache label doesn’t look the same
– MucaP
@And I’m gonna show you how I do it?
– MucaP
give more details, we’re not seeing your code work, you have to explain it right. But if you have changed and nothing appears, your problem is not the conversion, so change the definition of your problem or the question needs to be closed because it is not possible to play it. For me the button is not running. Put something in the method to indicate that you passed there. Go thrashing to see if you enter this method. There is no missing one
onClick="btn_Click"
?"`– Maniero
@mustache what else you need?
– MucaP