求助?为什么无法改变变量内容
为什么无法修改abc的值,单击第一个按钮,标签显示“原始”,单击第二个按钮显示“改变”,在单击第一个按钮,为什么显示“原始”
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class Default2 : System.Web.UI.Page
{
private static string abc;
protected void Page_Load(object sender, EventArgs e)
{
abc = "原始 ";
}
protected void Button1_Click(object sender, EventArgs e)
{
Label1.Text = abc;
}
protected void Button2_Click(object sender, EventArgs e)
{
abc = "改变 ";
Label1.Text = abc;
}
}
------解决方案--------------------因为每次Page_Load都会执行
------解决方案--------------------protected void Page_Load(object sender, EventArgs e)
{
if(!page.IsPostback)
{
abc = "原始 ";
}
}