自写控件中的重写LoadControlState事件为何不触发?

发布时间:2024-05-15 20:31 发布:上海旅游网

问题描述:

1.加载控件状态, OnInit;SaveControlState;都能触发只有LoadControlState无法触发.
2. 在OnInit 事件中已注册控件状态。
代码很多,我摘取了一些出来... 大概是这样情况, 请问是否有其它地方会影响到此事件的发生?

... ...
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
Page.RegisterRequiresControlState(this);
}

protected override object SaveControlState()
{
object baseState = base.SaveControlState();
object thisState = null;

if (authorValue != null)
{
thisState = ((IStateManager)kane).SaveViewState();
}

if (thisState != null)
{
return new Pair(baseState, thisState);
}
else
{
return baseState;
}
}

protected override void LoadControlState(object savedState)
{
if (savedState != null)
{
base.LoadControlState(savedState);
}

Pair p = savedState as Pair;
if (p != null)
{
base.LoadViewState(p.First);
((IStateManager)kane).LoadViewState(p.Second);
return;
}
base.LoadViewState(savedState);

}
举几个关键影响到这个错误的原因.
写个测试的页面来调用:

protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
mycontrol.kane = new mycontrol(obj0, obj1);
}
this.ClientScript.RegisterStartupScript(this.GetType(),
"alert",
"<script language='javascript'>window.alert('" + tb.Text + "::"+ mycontrol.kane.Excelcouth + "');</script>");
}

问题解答:

自写控件中的重写LoadControlState事件为何不触发?这个旅游问答期待您的解答,请登录账号或关注微信公众号回答这个问题。

热点新闻