Id like to create a web user control that inherits from System.Web.UI.WebControls.WebControl.
I implement IPostbackDataHandler
In the RenderContents method, I do the following
writer.AddAttribute(HtmlTextWriterAttribute.Name, Me.UniqueID & "$test")
writer.AddAttribute(HtmlTextWriterAttribute.Id, Me.ClientID & "_test")
writer.AddAttribute(HtmlTextWriterAttribute.Name, Me.UniqueID & "$test2")
writer.AddAttribute(HtmlTextWriterAttribute.Id, Me.ClientID & "_test2")
Notice the name of each textbox.
My implementation of the IPostbackDataHandler interface is as such:
Public Function LoadPostData(ByVal postDataKey As String, ByVal postCollection As System.Collections.Specialized.NameValueCollection) As Boolean Implements System.Web.UI.IPostBackDataHandler.LoadPostData
Public Sub RaisePostDataChangedEvent() Implements System.Web.UI.IPostBackDataHandler.RaisePostDataChangedEvent
Very simple, just stopping the app when I click a button NOT contained in the user control.
The question is why does this not work? Why when I place this user control on a web form along with a button and run it do I not hit either of those methods when I click the button.
While looking at examples I noticed that the name of the child controls, the textboxes in this case, need to be named me.UniqueID. So I did this for one of the text boxes and reran the project. When I clicked the button NOT in the user control the LoadPostData method was run.
So I changed the second textboxs name to me.UniqueID and ran the example. It worked fine but the value found in the postCollection was a concatenated string containing both values found in the text boxes.
I dont understand how to create server controls that have multiple textboxes, which responds to post backs raised by unrelated submits.
The underlying question is how does one create server controls that rely only on the render method to output the underlying HTML but have the ability to respond to postbacks?
Thanks you for any help that can be offered.