I'm working on a simple module, but I'm having some trouble with the scope of variables, and the firing of events. My module has a single view and nothing else. The form is test.ascx and the codebehind page is test.ascx.cs. My question is: Why when clicking buttons is myPhase continually being set to zero? What would I do to save the value of phase during the life of this page? Test.ascx: < %@ Control Language="C#" AutoEventWireup="true" CodeFile="Test.ascx.cs"
Inherits="Test" % > < asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" UseSubmitBehavior="False" / > < br / > < br / > < br / > < asp:Button ID="Button2" runat="server" Text="Button" OnClick="Button2_Click" UseSubmitBehavior="False" / > < br / > < br / > < br / > < asp:Label ID="Label1" runat="server" Text="Label"> test.ascx.cs: using System;
using System.Data;
public partial class Test : DotNetNuke.Entities.Modules.PortalModuleBase
{
public int myPhase;
private void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
myPhase = 1;
}
}
protected void Button1_Click(object sender, EventArgs e)
{
myPhase += 1;
UpdateLabel();
}
protected void Button2_Click(object sender, EventArgs e)
{
myPhase += 2;
UpdateLabel();
}
protected void UpdateLabel()
{
Label1.Text = myPhase.ToString();
}
} |