Child Control Won't Fire "OnPreRender"

C

Chad Stoker

I've been banging my head against the wall for hours trying to figure out
why the following code won't work.
I have a Control that is acting as a Container for a Custom Implementation
of the "Button" Web Control. The "OnPreRender" of the Custom Button isn't
even being called or executed! The "OnPreRender" of its Parent Container
Control is being executed just fine! What's the deal? I used the same code
in other projects and I didn't have this problem.

The only difference between my other code, and this code, is that I loaded
the Container from the ASPX code-behind, whereas here, I'm loading the
Container from within the Container. Why would that cause issues? Has anyone
ever heard of this?

<Default("Text")> ... blah ... blah ... blah> _
Public Class ContainerControlClass
Inherits System.Web.UI.WebControls.WebControl

Protected Overrides Sub OnPreRender(ByVal e as EventArgs)
Page.RegisterHiddenField("HiddenFieldBucket","")
End Sub

Protected Overrides Sub Render(ByVal output as System.Web.UI.HtmlTextWriter)
Dim i as integer
Build_Children_Custom_Buttons()
Me.RenderChildren(output)
End Sub

Private Sub Build_Children_Custom_Buttons()
Dim i As Integer

Dim startPoint As Integer = 65
Dim endPoint As Integer = 90
Dim range As Integer = endPoint - startPoint
Dim ae As New Text.ASCIIEncoding

For i = startPoint To endPoint
Dim newSubButton As CustomButton = New CustomButton
'Make The Letter For The Button.
newSubButton.Text = ae.GetString(New Byte(0) {i})
newSubButton.CssClass = Me.CssClass
newSubButton.HiddenFieldToChange = "HiddenFieldBucket"
Me.Controls.Add(newSubButton)
Next
End Sub

End Class



<Default("Text")> ... blah ... blah ... blah> _
Public Class CustomButton
Inherits System.Web.UI.WebControls.Button

Protected Overrides Sub OnPreRender(ByVal e as EventArgs)

'WHY CAN'T THIS BE CALLED CORRECTLY??!!

Page.RegisterClientScriptBlock("blah","<script></script>")
End Sub

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

End Class


Please help,

Thanks,
Chad
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,816
Latest member
SapanaCarpetStudio

Latest Threads

Top