H
hb
Hi,
I need to declare a variable who's value can be preserve through the same
ASP.Net page.
I tried the following code, only the static variable s2 keeps its value=22
after lnk1_Click
followed by lnk2_Click(). The others return to their original values
initiated during their
declaration. But the static variable's life doesn't end when the page is
closed and it causes
problem.
===
//======upsCont.aspx======
<%@ Page language="c#" Codebehind="upsCont.aspx.cs" AutoEventWireup="false"
Inherits="MyWeb.test.upsCont" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<html><head></head><body>
<form id="Form1" method="post" runat="server">
<asp:linkbutton runat="server" id="lnk1">link one</asp:linkbutton>
<br />
<asp:linkbutton runat="server" id="lnk2">link two</asp:linkbutton>
</form>
</body></html>
//========upsCont.aspx.cs=======
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace MyWeb.test
{
public class upsCont : System.Web.UI.Page
{
protected System.Web.UI.WebControls.LinkButton lnk1;
protected System.Web.UI.WebControls.LinkButton lnk2;
int s1=0;
static int s2=0;
protected int s3=0;
internal int s4=0;
public int s5=0;
protected internal int s6=0;
private void Page_Load(object sender, System.EventArgs e)
{
Response.Write("start:s1="+s1+"||s2="+s2+"||s3="+s3+"||s4="+s4+"||s5="+s5+"|
|s6="+s6+"<br>");
}
private void lnk1_Click(object sender, System.EventArgs e)
{
s1=11;
s2=22;
s3=33;
s4=44;
s5=55;
s6=66;
Response.Write("link1:s1="+s1+"||s2="+s2+"||s3="+s3+"||s4="+s4+"||s5="+s5+"|
|s6="+s6+"<br>");
}
private void lnk2_Click(object sender, System.EventArgs e)
{
Response.Write("link2:s1="+s1+"||s2="+s2+"||s3="+s3+"||s4="+s4+"||s5="+s5+"|
|s6="+s6+"<br>");
}
}
}
===
Are there any other types of variable that keep the variable's value updated
through the
same page and end the life of the variable when page is closed? ( I don't
want to use
neither cookies nor sessions)
Thank you
hb
I need to declare a variable who's value can be preserve through the same
ASP.Net page.
I tried the following code, only the static variable s2 keeps its value=22
after lnk1_Click
followed by lnk2_Click(). The others return to their original values
initiated during their
declaration. But the static variable's life doesn't end when the page is
closed and it causes
problem.
===
//======upsCont.aspx======
<%@ Page language="c#" Codebehind="upsCont.aspx.cs" AutoEventWireup="false"
Inherits="MyWeb.test.upsCont" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<html><head></head><body>
<form id="Form1" method="post" runat="server">
<asp:linkbutton runat="server" id="lnk1">link one</asp:linkbutton>
<br />
<asp:linkbutton runat="server" id="lnk2">link two</asp:linkbutton>
</form>
</body></html>
//========upsCont.aspx.cs=======
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace MyWeb.test
{
public class upsCont : System.Web.UI.Page
{
protected System.Web.UI.WebControls.LinkButton lnk1;
protected System.Web.UI.WebControls.LinkButton lnk2;
int s1=0;
static int s2=0;
protected int s3=0;
internal int s4=0;
public int s5=0;
protected internal int s6=0;
private void Page_Load(object sender, System.EventArgs e)
{
Response.Write("start:s1="+s1+"||s2="+s2+"||s3="+s3+"||s4="+s4+"||s5="+s5+"|
|s6="+s6+"<br>");
}
private void lnk1_Click(object sender, System.EventArgs e)
{
s1=11;
s2=22;
s3=33;
s4=44;
s5=55;
s6=66;
Response.Write("link1:s1="+s1+"||s2="+s2+"||s3="+s3+"||s4="+s4+"||s5="+s5+"|
|s6="+s6+"<br>");
}
private void lnk2_Click(object sender, System.EventArgs e)
{
Response.Write("link2:s1="+s1+"||s2="+s2+"||s3="+s3+"||s4="+s4+"||s5="+s5+"|
|s6="+s6+"<br>");
}
}
}
===
Are there any other types of variable that keep the variable's value updated
through the
same page and end the life of the variable when page is closed? ( I don't
want to use
neither cookies nor sessions)
Thank you
hb