Hi TS,
For ASP.NET server controls, the "Parent" property and "NamingContaine r",
they'll be set when being added into a certain ControlCollecti on. 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**********@n ospam.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.publi c.dotnet.framew ork.aspnet
| NNTP-Posting-Host: 103nat100.tea.s tate.tx.us 198.214.103.100
| Path: TK2MSFTNGXA01.p hx.gbl!TK2MSFTN GP08.phx.gbl!tk 2msftngp13.phx. gbl
| Xref: TK2MSFTNGXA01.p hx.gbl
microsoft.publi c.dotnet.framew ork.aspnet:1150 63
| X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet
|
| sorry to continue this again:
|
| The child control's CreateChildCont rols is fired as soon as the
| e.item.controls .Add method adds it
|
| thanks
|
| "TS" <ma**********@n ospam.nospam> wrote in message
| news:uh******** ******@TK2MSFTN GP12.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 (DataListItemEv entArgs e)
| >
| > {
| >
| > base.OnItemData Bound(e);
| >
| > Parameter parameter = (Parameter)e.It em.DataItem;
| >
| > try
| >
| > {
| >
| > Control control;
| >
| > if(parameter.Ty pe == ParameterType.C ontrol)
| >
| > control = this.Page.LoadC ontrol(paramete r.ControlPath);
| >
| > else
| >
| > {
| >
| > Assembly assembly = this.Page.GetTy pe().BaseType.A ssembly;
| >
| > //Assembly assembly =
| > Assembly.LoadFr om(@"C:\Tea\ACE S\_TEAMS\Web\bi n\TEA.Teams.Web .dll");
| >
| > control = (Control) assembly.Create Instance(parame ter.ControlType Name);
| >
| > }
| >
| > control.ID = parameter.Name;
| >
| > // Set up all the properties of this control from the
parameter.prope rties
| >
| > foreach(Diction aryEntry de in parameter.Prope rties)
| >
| > SetProperty(de. Key.ToString(), de.Value.ToStri ng(), control);
| >
| >
| > e.Item.Controls .Add(control);
| >
| > }
| >
| > catch (Exception ex)
| >
| > {
| >
| > throw new ApplicationExce ption("Unable to render criteria. Reason: " +
| > ex.Message, ex);
| >
| > }
| >
| > }
| >
| > "TS" <ma**********@n ospam.nospam> wrote in message
| > news:eu******** ******@TK2MSFTN GP15.phx.gbl...
| > > i can get handler and cast as page and that works though.
| > >
| > > (Page)HttpConte xt.Current.Hand ler
| > >
| > >
| > > "TS" <ma**********@n ospam.nospam> wrote in message
| > > news:Oo******** ******@tk2msftn gp13.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 CreateChildCont rols for the parent control until its
| > pre-render
| > > > event, so i know the parent control is on the page.
| > > >
| > > > Any ideas?
| > > >
| > > > thanks
| > > >
| > > >
| > >
| > >
| >
| >
|
|
|