Add control do page. What is going wrong here?

S

shapper

Hello,

On my Page_Init event I have the following:

Protected Sub Page_Init(ByVal sender As Object, ByVal e As EventArgs)
Handles MyBase.Init

Dim pContainer As New Panel
AddHandler pContainer.Init, AddressOf pContainer_Init
Me.Controls.Add(pContainer)

End Sub

And pContainer_Init is given by:

Private Sub pContainer_Init(ByVal sender As Object, ByVal e As
EventArgs)

' Find pContainer in page
Dim pContainer As Panel = CType(Page.FindControl("pContainer"),
Panel)

' Define pContainer properties
If Not (pContainer Is Nothing) Then
With pContainer
.CssClass = "pContainer"
.Text = "pContainer"
.Width = Unit.Pixel(760)
End With
Else
Response.Write("No Container/")
End If

End Sub

When I run it I can't see the panel. I get the string "NoContainer/"
as it wasn't found.

What am I doing wrong here?

Thanks,

Miguel
 
B

bruce barker \(sqlwork.com\)

you don't give the panel a ID when you create it, so there is no way to find
it by ID (name).

-- bruce(sqlwork.com)
 

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

Members online

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top