Problem setting a property of a user control

Discussion in 'ASP .Net' started by Karl Lang, Jun 17, 2004.

  1. Karl Lang

    Karl Lang Guest

    Hi, I'm trying to set a property of a user control that is part of another
    user control. So I have a control A which contains control B, and I'm trying
    to set a property in B from within the codebehind file for A.

    In control codebehind for A in page_load :
    Protected objButtons As ProductButtons

    objButtons = DirectCast(FindControl("ProductButtons1"), ProductButtons)
    objButtons.ProductID = 8

    In the ascx file for Control A
    <PRODUCTBUTTONSCTRL:pRODUCTBUTTONS id="ProductButtons1" runat="server"
    instance="1"/>

    Control B has a property called ProductID

    When I run the page I get "Object reference not set to an instance of an
    object" on the line objButtons.ProductID = 8

    Any ideas on how to get around this? can I reference the sub control B from
    within the aspx page that holds control A?

    klang
    Karl Lang, Jun 17, 2004
    #1
    1. Advertising

  2. "Karl Lang" <> wrote in message
    news:...
    > Hi, I'm trying to set a property of a user control that is part of another
    > user control. So I have a control A which contains control B, and I'm

    trying
    > to set a property in B from within the codebehind file for A.
    >
    > In control codebehind for A in page_load :
    > Protected objButtons As ProductButtons
    >
    > objButtons = DirectCast(FindControl("ProductButtons1"), ProductButtons)
    > objButtons.ProductID = 8
    >
    > In the ascx file for Control A
    > <PRODUCTBUTTONSCTRL:pRODUCTBUTTONS id="ProductButtons1" runat="server"
    > instance="1"/>
    >
    > Control B has a property called ProductID
    >
    > When I run the page I get "Object reference not set to an instance of an
    > object" on the line objButtons.ProductID = 8
    >
    > Any ideas on how to get around this? can I reference the sub control B

    from
    > within the aspx page that holds control A?


    In general, you should have control A expose a property which simply sets or
    gets the corresponding property of control B. That is, the property in A
    should delegate to B.
    --
    John Saunders
    johnwsaundersiii at hotmail
    John Saunders, Jun 17, 2004
    #2
    1. Advertising

  3. Karl Lang

    Karl Lang Guest

    "John Saunders" <> wrote in message
    news:%...
    > In general, you should have control A expose a property which simply sets

    or
    > gets the corresponding property of control B. That is, the property in A
    > should delegate to B.


    Thanks for the pointer John.
    Karl Lang, Jun 17, 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. Amir Eshterayeh

    Error Setting user control property at web form

    Amir Eshterayeh, Nov 27, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    529
    Amir Eshterayeh
    Nov 27, 2003
  2. Replies:
    0
    Views:
    347
  3. Nathan Sokalski
    Replies:
    25
    Views:
    1,409
    Nathan Sokalski
    Mar 4, 2010
  4. Amir Eshterayeh

    Error Setting user control property at web form

    Amir Eshterayeh, Nov 27, 2003, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    176
    Teemu Keiski
    Nov 27, 2003
  5. Dave

    Setting user control property dynamically?

    Dave, May 27, 2004, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    133
    Natty Gur
    May 28, 2004
Loading...

Share This Page