Property. Init and Load. Very strange error.

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
 
M

Mark Fitzpatrick

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.
 

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

Similar Threads

Property 1
TextBox and Property 1
Property 1
Property. 3
Property ... what am I doing wrong? 1
Property problem. Please, need some help on this. 1
Property is empty. Why? 2
Property 0

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top