referencing controls in controls

Discussion in 'ASP .Net Web Controls' started by DC Gringo, Sep 15, 2004.

  1. DC Gringo

    DC Gringo Guest

    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



    --
    _____
    DC G
    DC Gringo, Sep 15, 2004
    #1
    1. Advertising

  2. DC Gringo

    Karl Guest

    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/


    "DC Gringo" <> wrote in message
    news:OK2$...
    > 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
    >
    >
    >
    > --
    > _____
    > DC G
    >
    >
    >
    Karl, Sep 16, 2004
    #2
    1. Advertising

  3. DC Gringo

    DC Gringo Guest

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


    "Karl" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> wrote in
    message news:...
    > 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/
    >
    >
    > "DC Gringo" <> wrote in message
    > news:OK2$...
    > > 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
    > >
    > >
    > >
    > > --
    > > _____
    > > DC G
    > >
    > >
    > >

    >
    >
    DC Gringo, Sep 16, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. tim payne

    referencing controls

    tim payne, Aug 28, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    296
    Steve C. Orr, MCSD
    Aug 28, 2003
  2. Jim Corey

    Referencing controls on user controls

    Jim Corey, Jan 26, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    354
    Hermit Dave
    Jan 26, 2004
  3. 2obvious
    Replies:
    0
    Views:
    315
    2obvious
    Sep 13, 2004
  4. 2obvious
    Replies:
    2
    Views:
    373
    2obvious
    Jan 11, 2005
  5. DC Gringo

    referencing controls in controls

    DC Gringo, Sep 15, 2004, in forum: ASP .Net Building Controls
    Replies:
    2
    Views:
    131
    DC Gringo
    Sep 16, 2004
Loading...

Share This Page