注册 登录
编程论坛 ASP.NET技术论坛

关于viewstate状态视图

rgbtdkjcel 发布于 2009-10-08 17:13, 850 次点击
using System;
using System.Data;
using System.Configuration;
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 _Default : System.Web.UI.Page
{
   
        //public static string name
        //{
        //    get
        //    {
        //        return "姓名";
        //    }
        //}
  
   protected void Page_Load(object sender, EventArgs e)
   {
      
       TextBox tb = new TextBox();
       panel1.Controls.Add(tb);
       //tb.Text = "2";
       //tb.Text = (string)ViewState["first"];
       tb.BackColor = System.Drawing.Color.Red;
       if (!this.IsPostBack)
       {
           tb.Text = "1";
           ViewState["first"] = "rgbtdkjcel";
           tb.BackColor = System.Drawing.Color.Blue;
           
       }
       Response.Write(ViewState["first"]);
       button.Text = "bbb";
   }
   protected override void LoadViewState(object savedState)
   {
       button.Text = "aaa";
   }

    protected void button_Click(object sender, EventArgs e)
    {
        Response.Write((string)ViewState["first"]);
        TextBox one=(TextBox)panel1.Controls[0];
        one.Text = (string)ViewState["first"];
    }
  

}


当在页面中点击button按钮后,viewstate["first"]的值变空呢??
0 回复
1