Property. Init and Load. Very strange error.

  • Thread starter Thread starter shapper
  • Start date Start date
S

shapper

Hello,

I have a page and two user controls:

Page.aspx

|--- UserControl_1.ascx

|--- UserControl_2.ascx

In UserControl_2 I have a property defined as follows:

' Margin
Private _Margin As Integer
Public Property Margin() As Integer
Get
Return _Margin
End Get
Set(ByVal value As Integer)
_Margin = value
End Set
End Property ' Margin

In UserControl_1 I have the following:

Private Sub MyUserControl2_Init(ByVal sender As Object, ByVal e As
EventArgs) Handles MyUserControl2.Init

MyUserControl2.ID = "MyUserControl2"
MyUserControl2.Margin = 20

End Sub

However, in my UserControl_2 I am only able to access the property
values in Page_Load and not in Page_Init.

Any idea what might be going on?

This is really strange.

Thanks,

Miguel
 
It's the timing of events. All the inits aren't necessarily fired at the
same time. UserControl_1 has to create it's child controls so there's often
a dealy in when those properties are available. When UserControl_1 is
initializing that doesn't mean that UserControl_2 is initialized. In all
likelihood it will come as one of the next events. You may want to try using
the Trace.Write in the various controls so you can dump a message to the
trace log and get a feel for how and when the events are firing.
 
Back
Top