473,805 Members | 2,111 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(EventArg s e)
{

InitializeCompo nent();

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

// Set profile object to child control
this.profileCon trol.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(EventArg s 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 3590
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(EventArg s e)
{

InitializeCompo nent();

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

// Set profile object to child control
this.profileCon trol.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(EventArg s 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(EventArg s e)
{

InitializeCompo nent();

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

// Set profile object to child control
this.profileCon trol.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(EventArg s 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(EventArg s e)
{

InitializeCompo nent();

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

// Set profile object to child control
this.profileCon trol.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(EventArg s 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
1957
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 yes because on adding the control I would have thought that the OnInit, IPostBackDataHandler, etc calls would then be applied purely to that calendar, however it doesn't seem to be happening I'm getting around this at the moment by adding the...
5
2915
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 control. This field is initialized in Page_Load of every my page. This technique works with the exception that the title disappears every time a page is posted back. Could somebody explain me the reason, or suggest a better technique for setting page...
1
1224
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 public property. This works just fine. I have user controls that require the profile as well and I was coding it to work in the same way (created a class that inherits the System.Web.UI.UserControl class. It does the exact same thing as the...
1
2317
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, EnsureChildControls gets called, creating the control before the UserControl is even added to the webform. The problem with this is that the UniqueID of the custom control will be false, since OnInit has yet to be called on its parent, somehow...
3
1213
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); int x=1; }
6
29656
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 url is used by user and then display appropriate data to that url (one url is about fashion, other about law and so on). By means of recognition of url I can display appropriate banners for example.
4
2160
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" RepeatColumns="4" Width="100%" GridLines="Vertical"> <ItemTemplate>
3
1558
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 anybody thinks that is fine so plz describe me and send me any article or example for that. How can i do that
1
2093
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 relative to the hosting Page, and therefore if the following specific arrangement would even work. What I'm looking to do is dynamically insert multiple custom composite Web server controls onto a blank Page. This is no problem, I know how to do...
0
10614
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10369
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10109
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7649
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6876
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5544
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5678
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4327
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3847
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.