referencing controls in controls

D

DC Gringo

I am a bit twisted and need some straightening out. I have a webform with 3
controls on it: a mainHeader, a sectionHeader with a label control contained
in the mainHeader, and a topHeadline.

In the topHeadline, I am retrieving a value with a stored procedure. I need
to set that value to a label control within the sectionHeader like this:

mainHeader1.sectionHeader1.sectionHeaderLabel.Text = myVariable

In topHeadlines, I have:

Public countryName As String
Protected mainHeader1 As mainHeader
Protected sectionHeader1 As sectionHeader

(In Page Load): mainHeader1.sectionHeader1.sectionHeaderLabel.Text =
myVariable

The error I get is: "Object reference not set to an instance of an object."

What am I doing wrong?

_____
DC G
 
K

Karl

Your problem is that topHeadline doesn't know anything about mainHeader1 and
sectionHeader1....they are defined in the page, not topheadline. The trick
is to go through the page.

The page should have

public mainHeader1 as Mainheader
public sectionHeader1 as sectionHeader


your topHeadline should do:

ctype(Page, TYPEOFYOURPAGE).mainHeader1.sectionHeaderLabel.Text = myVariable


Also consider doing a pull (making the mainHeader1 get the data from
topheadline) instead of a push (passing the data from topheadline to
mainHeader1). Seems to me you have business logic in your presentation
layer. Whatever this data is that both user controls need should be placed
in a separate class and caching should be used (if appropriate)

Karl
 
D

DC Gringo

Karl, you're a genius!!! thanks!!
_____
DC G


Karl said:
Your problem is that topHeadline doesn't know anything about mainHeader1 and
sectionHeader1....they are defined in the page, not topheadline. The trick
is to go through the page.

The page should have

public mainHeader1 as Mainheader
public sectionHeader1 as sectionHeader


your topHeadline should do:

ctype(Page, TYPEOFYOURPAGE).mainHeader1.sectionHeaderLabel.Text = myVariable


Also consider doing a pull (making the mainHeader1 get the data from
topheadline) instead of a push (passing the data from topheadline to
mainHeader1). Seems to me you have business logic in your presentation
layer. Whatever this data is that both user controls need should be placed
in a separate class and caching should be used (if appropriate)

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/


with
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top