referencing controls in controls

  • Thread starter Thread starter DC Gringo
  • Start date Start date
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
 
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
 
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
 
Back
Top