controls getting values from another control---within a control

Discussion in 'ASP .Net Building 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. Hi, DC Gringo,

    My preferred approach is to create an interface and then implement it in all
    page classes that have the mentioned controls in them. In your case the
    interface will have one method in it:

    Public Interface IPageWithHeaders
    Public Sub SetLabelText(ByVal text As String)
    End Interface

    Then in the implementation in each page class you will access the control in
    sectionHeader (the recommended way is to expose the sectionHeaderLabel.Text
    as public string property of the sectionHeader class) and set its value to
    the value of the passed parameter.

    In topHeadline you will cast the Page property to your interface and call
    the method:

    DirectCast(Me.Page, IPageWithHeaders).SetLabelText(someValue)

    Hope this helps
    Martin
    "DC Gringo" <> wrote in message
    news:...
    > 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
    >
    >
     
    Martin Dechev, Sep 16, 2004
    #2
    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. DC Gringo
    Replies:
    0
    Views:
    304
    DC Gringo
    Sep 15, 2004
  2. Regan
    Replies:
    2
    Views:
    329
    Regan
    Mar 12, 2008
  3. Dave

    Limit what controls are allowed within another control?

    Dave, Sep 8, 2006, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    117
    Brennan Stehling
    Sep 11, 2006
  4. DC Gringo
    Replies:
    1
    Views:
    108
    Martin Dechev
    Sep 16, 2004
  5. Abe
    Replies:
    2
    Views:
    170
Loading...

Share This Page