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 就沒有意義了
轉載于:https://www.cnblogs.com/tutuzhang/archive/2011/04/08/2008905.html
總結
以上是生活随笔為你收集整理的LoadPostData 的一些注意事项的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 简单而不简陋﹣wp7视觉点滴
- 下一篇: 忽略NVRAM的config,修改cis