如我们所知,在Page_InitComplete事件中,我们可以更改视图状态,如何更改视图状态..pls帮助我 [英] As we know in Page_InitComplete event we can change view state,How can i change view state..pls help me

查看:119
本文介绍了如我们所知,在Page_InitComplete事件中,我们可以更改视图状态,如何更改视图状态..pls帮助我的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

protected void Page_InitComplete(object sender, EventArgs e)
       {
           // Raised by the  Page object.
           //Use this event for processing tasks that require all initialization be complete.
           //till view state not loaded hence use this event to make changes to view state
           StateBag v = ViewState;
           v.Add("Text", "changed");
          //what is the use of adding this name and value
       }

推荐答案

Page_InitComplete中,我的理解是ViewState 实际上并没有您要操纵的地方.与其像这样操作ViewState,不如改写SaveViewState 方法,最好是这样:
In Page_InitComplete, my understanding is that the ViewState is not actually there for you to manipulate. Rather than manipulate the ViewState like this, you would be better overriding the SaveViewState method like this:
protected override object SaveViewState()
{
  object[] vs = new object[2];
  vs[0] = base.SaveViewState(); // This gets the original viewstate
  vs[1] = _somethingToSave;

  return vs;
}


这篇关于如我们所知,在Page_InitComplete事件中,我们可以更改视图状态,如何更改视图状态..pls帮助我的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆