I need a field to store some information after one asp button click for another asp button’s click.
I saw that it wasn’t working so I wrote the following simple page codebehind (thinking that perhaps some of my code was causing it) but here I can see that the field really does get re-initialized.
I suppose that every button click reloads the page. Is this true? And if so – how can this be overcome without a static variable (-because what if more than one person is accessing the same page at once…)?
public partial class _Default : System.Web.UI.Page
{
string s = "a";
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
s = "b";
}
protected void Button2_Click(object sender, EventArgs e)
{
here.InnerText = s;// "here" is an id.
//returns "a" despite Button1 having been clicked before.
}
}
add in your code (EnableViewState)