473,388 Members | 1,499 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 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 3568
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: foldface | last post by:
Hi If I add a UserControl to a placeholder on a page during that pages PreRender stage and press a button on that UserControl will the postback for that button get processed? I would have thought...
5
by: Maxim Izbrodin | last post by:
Hello For displaying page titles for my ASP.NET applications I use the following technique <title><%=BannerModule.PageTitle%></title where BannerModule.PageTitle is a public field of my user...
1
by: AC | last post by:
I have a page class that inherits the System.Web.UI.Page class. Essentially what it does is load a user profile from a session (if it isn't loaded, it loads it into the session) and exposes it via a...
1
by: Kepler | last post by:
I have a custom control that is thrown onto a UserControl that is thrown onto a WebForm. Basically, I've got a scenario where if my UserControl sets an attribute on the custom control in the ascx,...
3
by: AC [MVP MCMS] | last post by:
I feel like I'm missing something so simple... I have a page (start.aspx) whose code behind is public class Start : AdminPage { override protected void OnInit(EventArgs e) { base.OnInit(e);...
6
by: Dariusz Tomon | last post by:
Hi How can I get url of page so taht I can pass it to string varaible. I have got several urls in my IIS under one folder. I want to have one default.aspx where code under it recognize which...
4
by: Sam Martin | last post by:
Hi, I have got a User Control that contains for the sake of argument, a single DataList control. eg. <asp:DataList id="DataListMain" runat="server" RepeatDirection="Horizontal"...
3
by: Mukesh | last post by:
Hi all I have to transfer a dataset and a string from a webform to a user control on the page without using viewstate or session or cookies . properties method is not working properly. if...
1
by: Jordan S. | last post by:
I'm just wondering if this would work. Please note that I'm not asking *how* to raise events. I'm clear on that. What I'm not clear on is the sequence in which events are raised by custom controls...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.