By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,473 Members | 3,505 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,473 IT Pros & Developers. It's quick & easy.

page or parent properties are null in server control

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.