例子:
protected virtual bool LoadPostData(string postDataKey,NameValueCollection postCollection)
{
string text = this.Text;
string str2 = postCollection[postDataKey];
if(!this.ReadOnly && !text.Equals(str2, StringComparison.Ordinal))
{
this.Text = str2;
return true;
}
return false;
}问题:
postDataKey应该是从表单数据中取出当前控件所包含的相应的<input>元素的数据的Key!根据论坛上朋友的指点,该postDataKey应该是该input的UniqueID。
如果一个自定义控件有两个<input>元素呢?又如何取得相应的数据?这里有另外一个例子,是VB的。
Public Function LoadPostData(ByVal postDataKey As String, ByVal postCollection As System.Collections.Specialized.NameValueCollection) As Boolean Implements System.Web.UI.IPostBackDataHandler.LoadPostData
_user = CType(postCollection(Me.UniqueID & ":User"), String)
_pass = CType(postCollection(Me.UniqueID & ":Pass"), String)
……这个VB的代码里postDataKey直接没有使用,而是根据默认的子控件的UniqueID生成的规则,因为默认的<input>元素的名字就是父控件的UniqueID:XXX的方式。那么这里的postDataKey又做何解?--------------------------
仍然是100分。我不知道我有没有讲明问题,大家帮忙搞定!
protected virtual bool LoadPostData(string postDataKey,NameValueCollection postCollection)
{
string text = this.Text;
string str2 = postCollection[postDataKey];
if(!this.ReadOnly && !text.Equals(str2, StringComparison.Ordinal))
{
this.Text = str2;
return true;
}
return false;
}问题:
postDataKey应该是从表单数据中取出当前控件所包含的相应的<input>元素的数据的Key!根据论坛上朋友的指点,该postDataKey应该是该input的UniqueID。
如果一个自定义控件有两个<input>元素呢?又如何取得相应的数据?这里有另外一个例子,是VB的。
Public Function LoadPostData(ByVal postDataKey As String, ByVal postCollection As System.Collections.Specialized.NameValueCollection) As Boolean Implements System.Web.UI.IPostBackDataHandler.LoadPostData
_user = CType(postCollection(Me.UniqueID & ":User"), String)
_pass = CType(postCollection(Me.UniqueID & ":Pass"), String)
……这个VB的代码里postDataKey直接没有使用,而是根据默认的子控件的UniqueID生成的规则,因为默认的<input>元素的名字就是父控件的UniqueID:XXX的方式。那么这里的postDataKey又做何解?--------------------------
仍然是100分。我不知道我有没有讲明问题,大家帮忙搞定!
假设控件拥有两个子控件,比如两个TextBox 一个用户名 一个密码
那这2个个TextBox各自在自己LoadPostData的时候回写数据2
VB这个 如果你是指 http://www.devedu.com/Doc/Asp/App/7025.aspx 内的代码这个控件 严格的说不是我们通常说的符合控件,因为他的子控件是在render方法内 “画”向浏览器的,我们并没有看到他在create child control 等。没有去实现INamingContainer接口,而是在件内 自己实现了 LoadPostData 方法 中的 数据
没有用 postDataKey 是因为他在render方法 指定了 客户端html内 name 的 值
writer.AddAttribute(HtmlTextWriterAttribute.Name, Me.UniqueID & ":Pass")
writer.AddAttribute(HtmlTextWriterAttribute.Name, Me.UniqueID & ":User")
他规定 用户名的input name= 用户名uniqeid:User 同样 密码是 密码UniqueID:Pass这是他自在render中自己规定了的 所以LoadPostData他也自己按照以前规定取回了。
即:在Render的时候Render了两个<input>的情况下,如何拿出两个input元素的值?