473,472 Members | 1,719 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

page or parent properties are null in server control

TS
When i try to access the page class or parent properties inside a server
control that is nested in another server control, they are null. I don't
even call CreateChildControls for the parent control until its pre-render
event, so i know the parent control is on the page.

Any ideas?

thanks
Nov 19 '05 #1
4 2412
TS
i can get handler and cast as page and that works though.

(Page)HttpContext.Current.Handler
"TS" <ma**********@nospam.nospam> wrote in message
news:Oo**************@tk2msftngp13.phx.gbl...
When i try to access the page class or parent properties inside a server
control that is nested in another server control, they are null. I don't
even call CreateChildControls for the parent control until its pre-render
event, so i know the parent control is on the page.

Any ideas?

thanks

Nov 19 '05 #2
TS
What happens is the control is added to the parent control's e.item property
during it's itemDataBind event. The aspx page calls this parent control's
databind method during page_Load. The parent control's code is as follows:

protected override void OnItemDataBound(DataListItemEventArgs e)

{

base.OnItemDataBound(e);

Parameter parameter = (Parameter)e.Item.DataItem;

try

{

Control control;

if(parameter.Type == ParameterType.Control)

control = this.Page.LoadControl(parameter.ControlPath);

else

{

Assembly assembly = this.Page.GetType().BaseType.Assembly;

//Assembly assembly =
Assembly.LoadFrom(@"C:\Tea\ACES\_TEAMS\Web\bin\TEA .Teams.Web.dll");

control = (Control) assembly.CreateInstance(parameter.ControlTypeName) ;

}

control.ID = parameter.Name;

// Set up all the properties of this control from the parameter.properties

foreach(DictionaryEntry de in parameter.Properties)

SetProperty(de.Key.ToString(), de.Value.ToString(), control);
e.Item.Controls.Add(control);

}

catch (Exception ex)

{

throw new ApplicationException("Unable to render criteria. Reason: " +
ex.Message, ex);

}

}

"TS" <ma**********@nospam.nospam> wrote in message
news:eu**************@TK2MSFTNGP15.phx.gbl...
i can get handler and cast as page and that works though.

(Page)HttpContext.Current.Handler
"TS" <ma**********@nospam.nospam> wrote in message
news:Oo**************@tk2msftngp13.phx.gbl...
When i try to access the page class or parent properties inside a server
control that is nested in another server control, they are null. I don't
even call CreateChildControls for the parent control until its pre-render event, so i know the parent control is on the page.

Any ideas?

thanks


Nov 19 '05 #3
TS
sorry to continue this again:

The child control's CreateChildControls is fired as soon as the
e.item.controls.Add method adds it

thanks

"TS" <ma**********@nospam.nospam> wrote in message
news:uh**************@TK2MSFTNGP12.phx.gbl...
What happens is the control is added to the parent control's e.item property during it's itemDataBind event. The aspx page calls this parent control's
databind method during page_Load. The parent control's code is as follows:

protected override void OnItemDataBound(DataListItemEventArgs e)

{

base.OnItemDataBound(e);

Parameter parameter = (Parameter)e.Item.DataItem;

try

{

Control control;

if(parameter.Type == ParameterType.Control)

control = this.Page.LoadControl(parameter.ControlPath);

else

{

Assembly assembly = this.Page.GetType().BaseType.Assembly;

//Assembly assembly =
Assembly.LoadFrom(@"C:\Tea\ACES\_TEAMS\Web\bin\TEA .Teams.Web.dll");

control = (Control) assembly.CreateInstance(parameter.ControlTypeName) ;

}

control.ID = parameter.Name;

// Set up all the properties of this control from the parameter.properties

foreach(DictionaryEntry de in parameter.Properties)

SetProperty(de.Key.ToString(), de.Value.ToString(), control);
e.Item.Controls.Add(control);

}

catch (Exception ex)

{

throw new ApplicationException("Unable to render criteria. Reason: " +
ex.Message, ex);

}

}

"TS" <ma**********@nospam.nospam> wrote in message
news:eu**************@TK2MSFTNGP15.phx.gbl...
i can get handler and cast as page and that works though.

(Page)HttpContext.Current.Handler
"TS" <ma**********@nospam.nospam> wrote in message
news:Oo**************@tk2msftngp13.phx.gbl...
When i try to access the page class or parent properties inside a server control that is nested in another server control, they are null. I don't even call CreateChildControls for the parent control until its pre-render event, so i know the parent control is on the page.

Any ideas?

thanks



Nov 19 '05 #4
Hi TS,

For ASP.NET server controls, the "Parent" property and "NamingContainer",
they'll be set when being added into a certain ControlCollection. Also
,from your description, the control you're developing seems to be a
databound control, and has the ItemDataBound event. If you added the
control in ItemDataBound event, then when do you check the control's parent
and found the value be null? It'll be much more helpful if you could
provide some further description on the custom control you're developing.

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)


--------------------
| From: "TS" <ma**********@nospam.nospam>
| References: <Oo**************@tk2msftngp13.phx.gbl>
<eu**************@TK2MSFTNGP15.phx.gbl>
<uh**************@TK2MSFTNGP12.phx.gbl>
| Subject: Re: page or parent properties are null in server control
| Date: Thu, 28 Jul 2005 17:57:27 -0500
| Lines: 97
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <#1**************@tk2msftngp13.phx.gbl>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: 103nat100.tea.state.tx.us 198.214.103.100
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msft ngp13.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet:115063
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| sorry to continue this again:
|
| The child control's CreateChildControls is fired as soon as the
| e.item.controls.Add method adds it
|
| thanks
|
| "TS" <ma**********@nospam.nospam> wrote in message
| news:uh**************@TK2MSFTNGP12.phx.gbl...
| > What happens is the control is added to the parent control's e.item
| property
| > during it's itemDataBind event. The aspx page calls this parent
control's
| > databind method during page_Load. The parent control's code is as
follows:
| >
| > protected override void OnItemDataBound(DataListItemEventArgs e)
| >
| > {
| >
| > base.OnItemDataBound(e);
| >
| > Parameter parameter = (Parameter)e.Item.DataItem;
| >
| > try
| >
| > {
| >
| > Control control;
| >
| > if(parameter.Type == ParameterType.Control)
| >
| > control = this.Page.LoadControl(parameter.ControlPath);
| >
| > else
| >
| > {
| >
| > Assembly assembly = this.Page.GetType().BaseType.Assembly;
| >
| > //Assembly assembly =
| > Assembly.LoadFrom(@"C:\Tea\ACES\_TEAMS\Web\bin\TEA .Teams.Web.dll");
| >
| > control = (Control) assembly.CreateInstance(parameter.ControlTypeName) ;
| >
| > }
| >
| > control.ID = parameter.Name;
| >
| > // Set up all the properties of this control from the
parameter.properties
| >
| > foreach(DictionaryEntry de in parameter.Properties)
| >
| > SetProperty(de.Key.ToString(), de.Value.ToString(), control);
| >
| >
| > e.Item.Controls.Add(control);
| >
| > }
| >
| > catch (Exception ex)
| >
| > {
| >
| > throw new ApplicationException("Unable to render criteria. Reason: " +
| > ex.Message, ex);
| >
| > }
| >
| > }
| >
| > "TS" <ma**********@nospam.nospam> wrote in message
| > news:eu**************@TK2MSFTNGP15.phx.gbl...
| > > i can get handler and cast as page and that works though.
| > >
| > > (Page)HttpContext.Current.Handler
| > >
| > >
| > > "TS" <ma**********@nospam.nospam> wrote in message
| > > news:Oo**************@tk2msftngp13.phx.gbl...
| > > > When i try to access the page class or parent properties inside a
| server
| > > > control that is nested in another server control, they are null. I
| don't
| > > > even call CreateChildControls for the parent control until its
| > pre-render
| > > > event, so i know the parent control is on the page.
| > > >
| > > > Any ideas?
| > > >
| > > > thanks
| > > >
| > > >
| > >
| > >
| >
| >
|
|
|

Nov 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: John Lau | last post by:
Hi, Is there documentation that talks about the page lifecycle, the lifecycle of controls on the page, and the rendering of inline code, in a single document? Thanks, John
2
by: eagle | last post by:
How do I access a control, like a placeholder, from another page, or another user control that may be on the same page. For instance, I have a web page with 2 user controls. One user controls...
1
by: Charles Zhang | last post by:
I created a custom server control that derives from WebControl. I found Parent and Page property are null for the control I created. But Parent is a readonly property so that I have no way to...
1
by: DJG79 | last post by:
Hi all, I am using an open source menu that i found and it works great, except for one thing that when the web page is not scrolled to the very top the drop down links will not stay visible. Has...
4
by: Ralf | last post by:
Here is my scenerio and what I am doing. I am open to other ways of doing this is it makes sense. I have a cell withing a row within a datagrid. When this cell is clicked (its a date field), I...
10
by: Benton | last post by:
Hi there, I have a UserControl with a couple of textboxes and a couple of buttons ("Save" and "Cancel"). The Click event for this buttons is in the UserControl's codebehind of course, so here's...
4
by: Rob Meade | last post by:
Hi all, I played with my first bit of AJAX the other week and was pleasantly surprised that I achieved my goal..now I'd like to try something else.. Question... If I have an updatePanel,...
4
by: evantay | last post by:
I'm using ASP.NET 2.0 with VS.NET 2005. I'm trying to access properties from my master pages within a page that inherits from that master page (a child page). However the values are always null....
1
by: Bali | last post by:
Default.aspx is the starting page containing a control(ascx) which has asp:button control on it. On the button click event it has to open a new page as a modal control. Since refreshing a page in...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.