Child Control Won't Fire "OnPreRender"

Discussion in 'ASP .Net Web Controls' started by Chad Stoker, Jun 8, 2004.

  1. Chad Stoker

    Chad Stoker Guest

    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
     
    Chad Stoker, Jun 8, 2004
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Umut Tezduyar
    Replies:
    1
    Views:
    415
    Steven Cheng[MSFT]
    Oct 6, 2004
  2. Chad
    Replies:
    4
    Views:
    8,422
  3. Jeff Rodriguez
    Replies:
    23
    Views:
    1,203
    David Schwartz
    Dec 9, 2003
  4. Matt T.

    Child OnPreRender method not being called.

    Matt T., Jan 7, 2004, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    177
    skilesare
    Jan 7, 2004
  5. Chad Stoker

    OnPreRender for Button Array Control

    Chad Stoker, Jun 8, 2004, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    158
Loading...

Share This Page