事件回传,数据回传(对不太明白数据回传的请看这里:ASP.NET 2.0服务器控件之处理回传数据 )
(a).要实现数据回传就要实现接口:IPostBackDataHandler
(b)要实现的方法如下:
bool IPostBackDataHandler.LoadPostData(string postDataKey, NameValueCollection postCollection)
{
string presentValue = this.Text;
string postedValue = postCollection[HiddenID];
// If two values don't match, then update the value.
if (!presentValue.Equals(postedValue))
{
this.Text = postedValue;
// Indicate the state of this control has changed.
return true;
}
// If there was no change in the data, then indicate that there is
// no change in state by returning false.
return false;
}
{
string presentValue = this.Text;
string postedValue = postCollection[HiddenID];
// If two values don't match, then update the value.
if (!presentValue.Equals(postedValue))
{
this.Text = postedValue;
// Indicate the state of this control has changed.
return true;
}
// If there was no change in the data, then indicate that there is
// no change in state by returning false.
return false;
}
void IPostBackDataHandler.RaisePostDataChangedEvent()
{
OnValueChanged(EventArgs.Empty);
}
{
OnValueChanged(EventArgs.Empty);
}
void OnValueChanged(EventArgs args)
{
// If the value has been changed, raise the event.
if (ValueChanged != null)
{
ValueChanged(this, args);
}
}
2.界面如下{
// If the value has been changed, raise the event.
if (ValueChanged != null)
{
ValueChanged(this, args);
}
}
3。代码下载
下载
欢迎大家加入 "小强控件园" ,有更多惊喜等着你,进入小强控件园
工欲善其事,必先利其器