日期:2014-05-17  浏览次数:20414 次

简单的点击按钮后问题
前台 <asp:Button ID="btnAddBusiness" Width="120px" runat="server" OnClick="btnAddBusiness_Click" Text="Submit" />

  public string fileName;
  protected void Page_Load(object sender, System.EventArgs e)
  {
  if (!Page.IsPostBack)
  {
  fileName = "1";
   
  }
 
  }


  protected void btnAddBusiness_Click(object sender, EventArgs e)
  {
  Response.Write(fileName); // 怎么点击按钮后 fileName 变成null 了?
   
  }

  怎么点击按钮后 fileName 变成null 了?

------解决方案--------------------
fileName赋一个初始值不就行了么
C# code

private string fileName="XX";

 protected void Page_Load(object sender, System.EventArgs e)
  {
  if (!Page.IsPostBack)
  {
  ViewState["FileName"]= "1";
    
  }
  
  }


  protected void btnAddBusiness_Click(object sender, EventArgs e)
  {
     Response.Write(this.FileName); 
  }