473,378 Members | 1,382 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,378 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 3566
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: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...

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.