什么变量放在viewstate里都对本页有效。

解决方案 »

  1.   

    不是阿,viewstate在页面刷新的时候就恢复到初始值了你是怎么用的 ?
      

  2.   

    int chgcount;
    private void Page_Load(object sender, System.EventArgs e)
    {
    chgcount=chgcount+1;
    if(ViewState["chgcount"]!=null)
    {
    if((int)this.ViewState["chgcount"] > 2)
    Response.Write("lock out");
    }
    else
      ViewState["chgcount"]=0 ;
    Response.Write(this.ViewState["chgcount"].ToString());
    }页面刷新时候,chgcount仍然是0,我想在页面刷新时候可以加1
    只有重新进来页面时候,chgcount才为零
      

  3.   

    if(!Page.IspostBack)
    {
    chgcount=chgcount+1;
    if(ViewState["chgcount"]!=null)
      {
        if((int)this.ViewState["chgcount"] > 2)
        Response.Write("lock out");
      }
    else
      {
        ViewState["chgcount"]=0 ;
        Response.Write(this.ViewState["chgcount"].ToString());
      }}
      

  4.   

    private void Page_Load(object sender, System.EventArgs e)
    {
        chgcount=chgcount+1;------>>>>改为:chgcount=(int)ViewState["chgcount"]+1 试试
    if(ViewState["chgcount"]!=null)
    {
    if((int)this.ViewState["chgcount"] > 2)
    Response.Write("lock out");
    }
    else
      ViewState["chgcount"]=0 ;
    Response.Write(this.ViewState["chgcount"].ToString());
    }GoodLuck!!
      

  5.   

    改成这样就可以~~public static int chgcount  ;
    private void Page_Load(object sender, System.EventArgs e)
    {
    ViewState["chgcount"] = chgcount;
    if(!Page.IsPostBack)
    {
    chgcount=(int)ViewState["chgcount"]+1; if(ViewState["chgcount"]!=null)
    {
    if(Convert.ToInt32(ViewState["chgcount"].ToString())>2)
    Response.Write("lock out");
    }
    else
    {
    ViewState["chgcount"]=0 ;
    Response.Write(this.ViewState["chgcount"].ToString());
    } }
      

  6.   

    public static int chgcount  ;
    你的变量应该定义成static
      

  7.   

    你加一个private不就行了,其它页面又不能调用
      

  8.   

    用internal声明
    如果只包含一个类,可以使用private声明