Reference a user controls properties from another user control??

Discussion in 'ASP .Net' started by =?Utf-8?B?YWJqb3Jr?=, May 5, 2004.

  1. I have a aspx page with two user controls. One of them holds some properties that I would like to set from the other user control. How do I do that

    I keep getting "Object reference not set to an instance of an object." when I declare the first user control like this from within the second UC

    Public formStandard As PIC.FormStandar
    ....
    formStandard.Market =
     
    =?Utf-8?B?YWJqb3Jr?=, May 5, 2004
    #1
    1. Advertising

  2. First of all, a UserControl should be an atomic object. By referencing
    properties of another user control (that you THINK will be on the page) from
    a user control, you are eliminating the possibility of using this user
    control on another page by itself, and the benefit of encapsulating content
    and code is gone. However, this is how you do it.

    From within the user control:
    ((UserControlType)Page.FindControl("idForUserControl")).Property = value;

    just switch the syntax to VB. Page.FindControl(". . .") is what you are
    looking for.
    -Jeffrey Palermo


    "abjork" <> wrote in message
    news:...
    > I have a aspx page with two user controls. One of them holds some

    properties that I would like to set from the other user control. How do I do
    that?
    >
    > I keep getting "Object reference not set to an instance of an object."

    when I declare the first user control like this from within the second UC:
    >
    > Public formStandard As PIC.FormStandard
    > ....
    > formStandard.Market = 4
    >
    >
    >
     
    Jeffrey Palermo, May 5, 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.

Share This Page