469,963 Members | 1,885 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,963 developers. It's quick & easy.

Property. Init and Load. Very strange error.

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

Feb 26 '07 #1
1 956
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.
--

Hope this helps,
Mark Fitzpatrick
Former Microsoft FrontPage MVP 199?-2006

"shapper" <md*****@gmail.comwrote in message
news:11**********************@z35g2000cwz.googlegr oups.com...
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

Feb 26 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Colin Robinson | last post: by
6 posts views Thread by Shimon Sim | last post: by
3 posts views Thread by Marty McFly | last post: by
4 posts views Thread by SandyIsCool | last post: by
1 post views Thread by shapper | last post: by
1 post views Thread by rainxy | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.