创建了自定义服务器控件
尝试将属性存储在视图状态但在回发时我无法获取先前存储在状态中的值。以下是代码
private int attachmentId;
public int AttachmentId
{
get { return attachmentId; }
set { attachmentId = value; }
}
private string attachmentName = string.Empty;
public string AttachmentName
{
get { return attachmentName; }
set { attachmentName = value; }
}
protected override void LoadViewState(object savedState)
{
object[] state = (object[])savedState;
base.LoadViewState(state[0]);
this.attachmentName = (string)state[1];
this.attachmentId = (int)state[2];
}
protected override void OnLoad(EventArgs e)
{
if(!IsPostBack)
{
this.AttachmentName ="HelloText.txt";
this.AttachmentID = 10;
}
}
protected override object SaveViewState()
{
object[] state = new object[3];
state[0] = base.SaveViewState();
state[1] = this.attachmentName;
state[2] = this.attachmentId;
return state;
}
在第一页加载值被添加到视图状态如果任何回发将发生值应该是可用的,现在没有发生任何可以帮助我