【发布时间】:2011-11-18 11:13:23
【问题描述】:
我想创建一个实现 IPostBackDataHandler 的标签,因为我想用 javascript 更改文本。如果我在那之后触发回发,那么我的文本就消失了。
我已有的代码是这样的:
public class CustomLabel : Label, IPostBackDataHandler
{
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
if (Page != null)
Page.RegisterRequiresPostBack(this);
}
public bool LoadPostData(string postDataKey, System.Collections.Specialized.NameValueCollection postCollection)
{
this.Text = postCollection[postDataKey];
return true;
}
public void RaisePostDataChangedEvent()
{
//throw new NotImplementedException();
}
}
它根本不起作用,我不明白我应该如何看到文本已更改并且 PostCollection[postDataKey] 始终为空。
【问题讨论】:
标签: asp.net custom-controls custom-server-controls