LoadPostData 的一些注意事项

LoadPostData是接口IPostBackDataHandler的方法

方法一般长这样

 public bool LoadPostData(string postDataKey, System.Collections.Specialized.NameValueCollection postCollection)
        {
            string strOldValue = Text;
            string strNewValue = postCollection[this.UniqueID];
            if (strOldValue == null || (strOldValue != null && !strOldValue.Equals(strNewValue)))
            {
                this.Text = strNewValue;
                return true;
            }
            return false;
        }

如果 返回true则 调用RaisePostDataChangedEvent()方法

但是 即使继承了IPostBackDataHandler接口,也并不是所有的 html控件都能引发 LoadPostData

比如 type=button (虽然可以用this.Page.RegisterRequiresPostBack(this);强制他执行LoadPostData,但是没有意义)

我想原因是 type=button的value 不会被post回服务器吧 ,因为LoadPostData方法中要用 postCollection[this.UniqueID]这样的方式去 得到控件新的值

既然无法post回服务器 那么 postCollection[this.UniqueID]肯定得到null 所以LoadPostData 就没有意义了

posted @ 2011-04-08 06:42  张土土  阅读(227)  评论(0编辑  收藏  举报