Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help: LoadPostData not firing

Status
Not open for further replies.

xpblueScreenOfDeath

Programmer
Sep 1, 2004
87
I can't figure out why LoadPostData is not firing. What am I doing wrong and how to fix it? When I force LoadPostData to fire by calling RegisterRequiresPostBack, but for some reason the values is blank even though I typed in a value before the postback.

heres the output for the response.write in the OnPreRender when I force it to fire:
<Code>
LoadPostData
WebCustomControl11

</Code>

here is what got render for the control:
<Code>
<span id="WebCustomControl11"><input name="WebCustomControl11:dataArr" id="WebCustomControl11_dataArr" type="text" /></span>
</Code>

heres the code:
<Code>
Imports System.ComponentModel
Imports System.Web.UI

<DefaultProperty("Text"), ToolboxData("<{0}:WebCustomControl1 runat=server></{0}:WebCustomControl1>")> Public Class WebCustomControl1
Inherits System.Web.UI.WebControls.WebControl
Implements INamingContainer, IPostBackDataHandler

Dim text As System.Web.UI.HtmlControls.HtmlInputText

Protected Overrides Sub CreateChildControls()
text = New System.Web.UI.HtmlControls.HtmlInputText
text.ID = "dataArr"

Controls.Add(text)
End Sub

Protected Overrides Sub OnPreRender(ByVal e As EventArgs)
If Not (Page Is Nothing) Then
Page.RegisterRequiresPostBack(Me)
End If
End Sub

Protected Overrides Sub Render(ByVal output As System.Web.UI.HtmlTextWriter)
MyBase.Render(output)
End Sub

Public Function LoadPostData(ByVal postDataKey As String, ByVal postCollection As System.Collections.Specialized.NameValueCollection) As Boolean Implements System.Web.UI.IPostBackDataHandler.LoadPostData
Dim value = postCollection(postDataKey)

Page.Response.Write("LoadPostData<BR>")
Page.Response.Write(postDataKey & "<BR>")
Page.Response.Write(value & "<BR>")
If Not (text Is Nothing) And text.Value <> value Then
text.Value = value
End If
End Function

Public Sub RaisePostDataChangedEvent() Implements System.Web.UI.IPostBackDataHandler.RaisePostDataChangedEvent

End Sub
End Class
</Code>
 
Have you examined postCollection to see if there's actually a cooresponding value for postDataKey? Maybe it's misnamed or something.

Out of curiosity, however, why not just use the TextBox server control and let it handle all the nitty-gritty mechanics?
 
Because what I gave is only an example. I am not trying to recreate the textbox server control. I am creating a more complex control that doesn't use a textbox, but I still have the same problem with the LoadPostData not firing. And ofcourse, a simple example is probably easier to figure out than a more complex example. I read through the documentation and still could figure it out.

From the example you can see that the postDataKey is WebCustomControl11, but the key is suppose to be WebCustomControl11:dataArr. WebCustomControl11:dataArr is one of the keys in the postCollection, when I message out all the keys. I just want to know the correct way of doing it so that postDataKey match one of the keys in the postCollection. I also read some where that if the postDataKey is not a key in the postCollection then the LoadPostData event won't fire and that is exactly what is happening, and that is why I force it to fire for debuging purposes.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top