K
kbutterly
Good afternoon all,
I have created a custom control which is a simple address control. The
control does not have a button in it; just the controls for the name
and address fields.
The control renders great when I add it to a web form, but when I
submit the form, I lose the data.
Now, I know that this has to do with post backs.
So, question #1: do I need to implement IPostBackDataHandler? If so,
then I know that I need to have LoadPostData and
RaisePostDataChangedEvent code. Unfortunately, I can't seem to find
any sample code for LoadPostData for a control with multiple controls
of different types, so I need some guidance in that area.
question #2: should I be using the Render or RenderContents method? I
am currently using RenderContents and I have lots of code like this:
output.AddAttribute("class", "row")
output.RenderBeginTag(HtmlTextWriterTag.Div) 'begin row div
output.AddAttribute("class", "firstCol")
output.RenderBeginTag(HtmlTextWriterTag.Div) 'begin firstcol div
output.RenderBeginTag(HtmlTextWriterTag.Label) 'begin label
output.Write("First")
output.RenderEndTag() 'end label
output.RenderEndTag() 'end firstcol
...etc...
However, I found an example in MSDN that just used the Render method. I
_think_ that I need the RenderContents method for the attributes???
Here is the bare outline of my custom control:
Namespace myCustomControls
<ToolboxData("<{0}:myAddressControl
runat=server></{0}:myAddressControl>")> _
Public Class myAddressControl
Inherits CompositeControl
Private txtFirstName As TextBox
Private txtLastName As TextBox
Private txtAddress1 As TextBox
Private txtAddress2 As TextBox
Private txtCity As TextBox
Private ddlState As DropDownList
Private txtZip As TextBox
Private _secondAddressLine As Boolean
Private arrStates() As String = {"Alabama", "Alaska", ..., "Wyoming"}
Property FirstName() As String
End Property
Property LastName() As String
End Property
Property Address1() As String
End Property
Property Address2() As String
End Property
Property City() As String
End Property
Property State() As String
End Property
Property Zip() As String
End Property
Public Property showSecondAddress() As Boolean
End Property
Protected Overrides Sub CreateChildControls()
End Sub
Protected Overrides Sub RenderContents(ByVal output As
HtmlTextWriter)
End Sub
Protected Overrides ReadOnly Property TagKey() As
System.Web.UI.HtmlTextWriterTag
End Property
End Class
End Namespace
I am hoping that I am just missing something very basic or just making
a stupid newbie error.
Any references, resources, or other assistance would be greatly
appreciated!
Thanks,
Kathryn
I have created a custom control which is a simple address control. The
control does not have a button in it; just the controls for the name
and address fields.
The control renders great when I add it to a web form, but when I
submit the form, I lose the data.
Now, I know that this has to do with post backs.
So, question #1: do I need to implement IPostBackDataHandler? If so,
then I know that I need to have LoadPostData and
RaisePostDataChangedEvent code. Unfortunately, I can't seem to find
any sample code for LoadPostData for a control with multiple controls
of different types, so I need some guidance in that area.
question #2: should I be using the Render or RenderContents method? I
am currently using RenderContents and I have lots of code like this:
output.AddAttribute("class", "row")
output.RenderBeginTag(HtmlTextWriterTag.Div) 'begin row div
output.AddAttribute("class", "firstCol")
output.RenderBeginTag(HtmlTextWriterTag.Div) 'begin firstcol div
output.RenderBeginTag(HtmlTextWriterTag.Label) 'begin label
output.Write("First")
output.RenderEndTag() 'end label
output.RenderEndTag() 'end firstcol
...etc...
However, I found an example in MSDN that just used the Render method. I
_think_ that I need the RenderContents method for the attributes???
Here is the bare outline of my custom control:
Namespace myCustomControls
<ToolboxData("<{0}:myAddressControl
runat=server></{0}:myAddressControl>")> _
Public Class myAddressControl
Inherits CompositeControl
Private txtFirstName As TextBox
Private txtLastName As TextBox
Private txtAddress1 As TextBox
Private txtAddress2 As TextBox
Private txtCity As TextBox
Private ddlState As DropDownList
Private txtZip As TextBox
Private _secondAddressLine As Boolean
Private arrStates() As String = {"Alabama", "Alaska", ..., "Wyoming"}
Property FirstName() As String
End Property
Property LastName() As String
End Property
Property Address1() As String
End Property
Property Address2() As String
End Property
Property City() As String
End Property
Property State() As String
End Property
Property Zip() As String
End Property
Public Property showSecondAddress() As Boolean
End Property
Protected Overrides Sub CreateChildControls()
End Sub
Protected Overrides Sub RenderContents(ByVal output As
HtmlTextWriter)
End Sub
Protected Overrides ReadOnly Property TagKey() As
System.Web.UI.HtmlTextWriterTag
End Property
End Class
End Namespace
I am hoping that I am just missing something very basic or just making
a stupid newbie error.
Any references, resources, or other assistance would be greatly
appreciated!
Thanks,
Kathryn