473,802 Members | 1,955 Online
Bytes | Software Development & Data Engineering Community
+ 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 CreateChildCont rols 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 2451
TS
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

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 (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


Nov 19 '05 #3
TS
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



Nov 19 '05 #4
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
| > > >
| > > >
| > >
| > >
| >
| >
|
|
|

Nov 19 '05 #5

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

Similar topics

2
3633
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
2058
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 contains a placeholder to that will contain any error messages to be displayed. If the first user control creates an error, I want to be able to push that error to the 2nd control to display it at the placeholder. I have tried Dim ctrlError as...
1
1502
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 assign it a proper value. By the way, I did no create a constructor for my custom control. I did not override OnInit() method as well. Could some one point out what I am doing wrong.
1
2072
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 anyone else had this sort of problem with javascript? and any ideas how to fix it would be greatly appreciated.. I have included a copy of the code below, thanks. /**
4
8372
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 want a calendar to pop up to change the date. So, I had to added an onclick event to the cell, which runs a javascript function when it the click happens. The javascript function does the showModalDialog to open the Calendar.aspx page and pass...
10
2431
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 my question. Once the UserControl is dropped onto the container page, how can I perform some action on the codebehind of the container page from the codebehind of the UserControl? For instance, suppose that the UserControl is dropped inside one...
4
2553
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, and lets say I have a button as a trigger which runs a function in my code behind to add a textbox to the updatePanel, when the form is submitted does this control actually "exist" as such on the
4
4021
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. In my masterpage I have this: private bool m_AlreadyTested; public bool AlreadyTested { get { return m_AlreadyTested; }
1
9414
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 a dialog box ended up opening up a new browser window with the aspx page, I read on a forum that I should use the iframe control and since I have to open a bunch of pages as diaogboxes, I created a general page(Container.aspx) which has an...
0
9699
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10538
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...
0
10305
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10285
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
9115
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6838
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
5622
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3792
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2966
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.