473,320 Members | 1,838 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Can't find control

Hello,

I added a content place holder (ID="cphContent") to a master page.

Now I need to add controls to that content place holder in the pages
which use that master page.

I am doing it at runtime as follows

Dim cphContent As ContentPlaceHolder =
CType(Page.FindControl("cphContent"), ContentPlaceHolder)
Dim MyLabel As New Label
AddHandler MyLabel.Init, AddressOf MyLabel_Init
cphContent.Controls.Add(MyLabel)

I am getting an error:

"System.NullReferenceException: Object reference not set to an
instance of an object."

I think I am getting the error because my the cphContent content place
holder is not found.

Could you tell me how to solve this?

Thanks,

Miguel

Nov 7 '06 #1
2 1590
Hi,

shapper wrote:
I added a content place holder (ID="cphContent") to a master page.

Now I need to add controls to that content place holder in the pages
which use that master page.

I am doing it at runtime as follows

Dim cphContent As ContentPlaceHolder =
CType(Page.FindControl("cphContent"), ContentPlaceHolder)
Dim MyLabel As New Label
AddHandler MyLabel.Init, AddressOf MyLabel_Init
cphContent.Controls.Add(MyLabel)

I am getting an error:

"System.NullReferenceException: Object reference not set to an
instance of an object."

I think I am getting the error because my the cphContent content place
holder is not found.
is your ContentPlaceHolder itself contained within another control? You'll
need to specify the complete "path" to your CPH. In other words, if you use
FindControl with nested controls, you'll have to do a recursive search.

Cheers,
Olaf
--
My .02: www.Resources.IntuiDev.com
Nov 7 '06 #2
This probably won't solve your problem, but it's worth a shot...

Change that line to: CType(FindControl("cphContent"),
ContentPlaceHolder)

Nov 7 '06 #3

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

Similar topics

8
by: Yasutaka Ito | last post by:
Hi, Is there a way to find to which control the current control is docked against? For example, let's say I have panel1 and panel2 docked to left within a form. The panel1 is the first one on...
3
by: P.L. | last post by:
Hi! I have problem with Datarepeater control. When I load template from external aspx file ItemTemplate = Page.LoadTemplate(....); I can't find control in ItemDataBound event. ...
1
by: bill yeager | last post by:
I have a datagrid control within a datalist control. When I try and do a "Find" on the control, the object comes back with nothing and then my pgm crashes. I am 100% sure that my datagird inside...
2
by: TM | last post by:
What is the method used to find all asp.net server controls (run at server) such as TextBox, ListBox, CheckBox... currently defined on an Asp.Net page at run time. I need it inside of a controlled...
10
by: Sacha Korell | last post by:
I'm trying to load a drop-down list with all DropDownList control names from another page. How would I be able to find those DropDownList controls? The FindControl method will only find a...
12
by: Marc | last post by:
Hi, How can i increase the mousehover event timer? AddHandler NewBtn.MouseHover, AddressOf Shownotes Private Sub Shownotes(ByVal sender As System.Object, ByVal e As System.EventArgs)...
1
by: Salim | last post by:
Hi, I'm trying to get UniqueID of a linkbutton. I have 2 web user controls. And a master page. In fisrst web user control there is a datalist. In datalist ItemCreated event, I try to find...
3
by: ma | last post by:
Hello, I download AJAXToolKit today and install it and configured my MSVC 2005 to use it. But there is no TabPanle control in it. I had an installation some month ago and it had TabPanel control...
5
by: gnewsgroup | last post by:
In my user control, I would like to find a Label control in the parent page (the page that uses my user control). I need to update that Label.Text when something happens in the user control. I...
7
by: =?Utf-8?B?V2ViQnVpbGRlcjQ1MQ==?= | last post by:
i have a master page and aseries of controls labeled fn1, fn2, fn3 , ... i want ot loop and use find control but i'm finding them. i'm using the following w/o luck ContentPlaceHolder cph =...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.