471,591 Members | 2,061 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,591 software developers and data experts.

Page / UserControl OnInit Problem

Hi,

how you people handle that issue:

you have one page and one control.
in your page, you load some kind of object based on the given
parameter:

Page:

protected override void OnInit(EventArgs e)
{

InitializeComponent();

// Get Profile
this.profile = (UserProfile)EntityCache.Get ( Request["profileId"] );

// Set profile object to child control
this.profileControl.Profile = this.profile
}

------------------------

...in your control, you need that profile object the page already got

Control:

private UserProfile profile;

public UserProfile Profile
{
get { return this.profile; }
set { this.profile = value; }
}
protected override void OnInit(EventArgs e)
{
// Do something with the profile object
Populate( this.Profile );
}

------------------------

now here is the problem:
the OnInit Event in the control is always fired first,
so i have no chance to load the profile object in the Page and then set
it to the control, so now it leads that the profile object in the
control is always null.

i could solve that by moving the OnInit code in the control, to the
Page_Load, but i need that code in the OnInit Event due custom
events...

how you guys handle that?

thanks,
gregor

Jun 9 '06 #1
3 3462
How about having the control get the profile from its parent Page, rather
than the other way around? You could do it in the Load event.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"gr************@gmail.com" wrote:
Hi,

how you people handle that issue:

you have one page and one control.
in your page, you load some kind of object based on the given
parameter:

Page:

protected override void OnInit(EventArgs e)
{

InitializeComponent();

// Get Profile
this.profile = (UserProfile)EntityCache.Get ( Request["profileId"] );

// Set profile object to child control
this.profileControl.Profile = this.profile
}

------------------------

...in your control, you need that profile object the page already got

Control:

private UserProfile profile;

public UserProfile Profile
{
get { return this.profile; }
set { this.profile = value; }
}
protected override void OnInit(EventArgs e)
{
// Do something with the profile object
Populate( this.Profile );
}

------------------------

now here is the problem:
the OnInit Event in the control is always fired first,
so i have no chance to load the profile object in the Page and then set
it to the control, so now it leads that the profile object in the
control is always null.

i could solve that by moving the OnInit code in the control, to the
Page_Load, but i need that code in the OnInit Event due custom
events...

how you guys handle that?

thanks,
gregor

Jun 9 '06 #2
well, that would be an solution too,
but if i have one page and multiple controls, i'd like to prevent code
duplication.

i'd like also let the control be independant, so i could use it at
other places, where the parameter or whatever would be different.
gregor.
Peter schrieb:
How about having the control get the profile from its parent Page, rather
than the other way around? You could do it in the Load event.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"gr************@gmail.com" wrote:
Hi,

how you people handle that issue:

you have one page and one control.
in your page, you load some kind of object based on the given
parameter:

Page:

protected override void OnInit(EventArgs e)
{

InitializeComponent();

// Get Profile
this.profile = (UserProfile)EntityCache.Get ( Request["profileId"] );

// Set profile object to child control
this.profileControl.Profile = this.profile
}

------------------------

...in your control, you need that profile object the page already got

Control:

private UserProfile profile;

public UserProfile Profile
{
get { return this.profile; }
set { this.profile = value; }
}
protected override void OnInit(EventArgs e)
{
// Do something with the profile object
Populate( this.Profile );
}

------------------------

now here is the problem:
the OnInit Event in the control is always fired first,
so i have no chance to load the profile object in the Page and then set
it to the control, so now it leads that the profile object in the
control is always null.

i could solve that by moving the OnInit code in the control, to the
Page_Load, but i need that code in the OnInit Event due custom
events...

how you guys handle that?

thanks,
gregor


Jun 9 '06 #3
so there is no clean solution for that?
that's pretty weak...


gr************@gmail.com schrieb:
well, that would be an solution too,
but if i have one page and multiple controls, i'd like to prevent code
duplication.

i'd like also let the control be independant, so i could use it at
other places, where the parameter or whatever would be different.
gregor.
Peter schrieb:
How about having the control get the profile from its parent Page, rather
than the other way around? You could do it in the Load event.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"gr************@gmail.com" wrote:
Hi,

how you people handle that issue:

you have one page and one control.
in your page, you load some kind of object based on the given
parameter:

Page:

protected override void OnInit(EventArgs e)
{

InitializeComponent();

// Get Profile
this.profile = (UserProfile)EntityCache.Get ( Request["profileId"] );

// Set profile object to child control
this.profileControl.Profile = this.profile
}

------------------------

...in your control, you need that profile object the page already got

Control:

private UserProfile profile;

public UserProfile Profile
{
get { return this.profile; }
set { this.profile = value; }
}
protected override void OnInit(EventArgs e)
{
// Do something with the profile object
Populate( this.Profile );
}

------------------------

now here is the problem:
the OnInit Event in the control is always fired first,
so i have no chance to load the profile object in the Page and then set
it to the control, so now it leads that the profile object in the
control is always null.

i could solve that by moving the OnInit code in the control, to the
Page_Load, but i need that code in the OnInit Event due custom
events...

how you guys handle that?

thanks,
gregor


Jun 12 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Maxim Izbrodin | last post: by
3 posts views Thread by AC [MVP MCMS] | last post: by
6 posts views Thread by Dariusz Tomon | last post: by
1 post views Thread by Jordan S. | last post: by
reply views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by
reply views Thread by Anwar ali | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.