north2012
Member level 3
- Joined
- Apr 1, 2013
- Messages
- 63
- Helped
- 1
- Reputation
- 2
- Reaction score
- 1
- Trophy points
- 1,288
- Activity points
- 1,813
I am very new to ASP.NET but I have background in C and C#. I am trying to make web application which will be connected with my database. I did that and that is OK. The problem occurred when I added buttons for moving forward and backward through the database... It was working fine but only for one click! Then I thought that probably I have bug in the code and I decided to do it in easy way.
I created new web form with just one button and one label, but behavior is still the same- after first click event is not fired again.
My code
and source
Any help?
Thanks.
- - - Updated - - -
I created new web form with just one button and one label, but behavior is still the same- after first click event is not fired again.
My code
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace DummyTest
{
public partial class WebForm1 : System.Web.UI.Page
{
int pom = 0;
protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = Convert.ToString(pom);
}
protected void Button1_Click(object sender, EventArgs e)
{
pom++;
Label1.Text = Convert.ToString(pom);
}
}
}
and source
Code:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="DummyTest.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
Dummy Test<br />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<br />
</div>
</form>
</body>
</html>
Any help?
Thanks.
- - - Updated - - -
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace DummyTest
{
public partial class WebForm1 : System.Web.UI.Page
{
static int pom;
protected void Page_Load(object sender, EventArgs e)
{
if (Page.IsPostBack == false)
{
pom = 0;
Label1.Text = Convert.ToString(pom);
}
}
protected void Button1_Click(object sender, EventArgs e)
{
var pom = Int32.Parse(Label1.Text);
pom++;
Label1.Text = Convert.ToString(pom);
}
protected void Button2_Click(object sender, EventArgs e)
{
var pom = Int32.Parse(Label1.Text);
pom--;
Label1.Text = Convert.ToString(pom);
}
}
}