|
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 | |
Share:
|
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
| | |
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
| | |
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
| | This discussion thread is closed Replies have been disabled for this discussion. Similar topics
6 posts
views
Thread by foldface@yahoo.co.uk |
last post: by
|
5 posts
views
Thread by Maxim Izbrodin |
last post: by
|
1 post
views
Thread by AC |
last post: by
|
1 post
views
Thread by Kepler |
last post: by
|
3 posts
views
Thread by AC [MVP MCMS] |
last post: by
|
6 posts
views
Thread by Dariusz Tomon |
last post: by
|
4 posts
views
Thread by Sam Martin |
last post: by
|
3 posts
views
Thread by Mukesh |
last post: by
|
1 post
views
Thread by Jordan S. |
last post: by
| | | | | | | | | | |