Hi Adrian,
Welcome the ASP.NET newsgroup.
As for the custom composite control developing problem you mentioned, I
think you can try checking the following things first:
1. Make sure your custom composite control class has implemented the
"INamingContain er" interface, this is very important for custom control
which will contain nested child controls.
2. In the "CreateChildCon trols" function, if you want to assign some
initial value for some certain sub controls' property, make sure you set
value after the sub control has been added into the container's control
collection.
As for postback event, from the code you provided, I think it should be ok
and I haven't found anything incorrect in the function. Therefore, the
problem could be caused by anything else in the control. Anyway, I've
pasted the code of my test control which runs correctly in my local
project, you can have a test on your side to see whether it works:
=============== =============== ====
Imports System
Imports System.Collecti ons.Generic
Imports System.Componen tModel
Imports System.Text
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.W ebControls
<DefaultPropert y("Text"), ToolboxData("<{ 0}:WebCustomCon trol1
runat=server></{0}:WebCustomCo ntrol1>")> _
Public Class WebCustomContro l1
Inherits WebControl
Implements INamingContaine r
Private _panel As Panel
Private _txt1 As TextBox
Private _txt2 As TextBox
<Bindable(True) , Category("Appea rance"), DefaultValue("" ),
Localizable(Tru e)> Property Text() As String
Get
Dim s As String = CStr(ViewState( "Text"))
If s Is Nothing Then
Return String.Empty
Else
Return s
End If
End Get
Set(ByVal Value As String)
ViewState("Text ") = Value
End Set
End Property
Protected Overrides Sub CreateChildCont rols()
Controls.Clear( )
_panel = New Panel()
_panel.ID = "plMain"
Controls.Add(_p anel)
_txt1 = New TextBox()
_txt1.ID = "txt1"
_txt1.AutoPostB ack = True
AddHandler _txt1.TextChang ed, AddressOf TextBox_TextCha nged
Controls.Add(_t xt1)
_txt2 = New TextBox()
_txt2.ID = "txt2"
_txt2.AutoPostB ack = True
AddHandler _txt2.TextChang ed, AddressOf TextBox_TextCha nged
Controls.Add(_t xt2)
If Not Page.IsPostBack Then
_txt1.Text = "Textbox1 initial text"
_txt2.Text = "Textbox2 initial text"
End If
End Sub
Private Sub TextBox_TextCha nged(ByVal sender As Object, ByVal e As
EventArgs)
Page.Response.W rite("<br/>" & sender.ID & ", new text: " &
sender.Text)
End Sub
End Class
=============== =============== ===========
Hope this helps.
Regards,
Steven Cheng
Microsoft Online Support
Get Secure!
www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)