首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

LoadViewState不执行,为什么?解决方案

2012-02-10 
LoadViewState不执行,为什么?public class CartLoader : System.Web.UI.WebControls.WebControl{private s

LoadViewState不执行,为什么?
public class CartLoader : System.Web.UI.WebControls.WebControl
  {
  private string text;

  public string Text
  {
  get 
  {  
  return text;
  }
  set 
  {
  text = value;
  }
  }

  protected override void LoadViewState(object savedState)
  {
  text = savedState.ToString();
  }

  protected override object SaveViewState()
  {
  return text;
  }

  protected override void Render(HtmlTextWriter output)
  {
  output.Write("<input type= text id='txt_"+ this.UniqueID+"' value='"+Text+"' />");
  output.Write("<input type= submit id='" + this.UniqueID + "' value='324' />");
   
  }
  }

 一个简单的例子,想保存用户输入的值,但页面提交时LoadViewState没执行,所以值没了,怎么让LoadViewState执行??????

[解决办法]
如果你覆盖一个父类方法,例如:

C# code
               protected override void abcd(......)         {             base.abcd(.....);            .........        } 

热点排行