stuck: I cant reach usercontrol's class ..

Discussion in 'ASP .Net Web Controls' started by Support, Mar 24, 2005.

  1. Support

    Support Guest

    in asp.net
    If I have a web usercontrol WUC with code behind Class CLASSWUC
    and I have a web page that loads the control

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles MyBase.Init
    MANAGEGENERAL = LoadControl("WUC.ascx")
    MyPlaceholder.Controls.Add(MANAGEGENERAL)
    InitializeComponent()
    End Sub

    And if in CLASSWUC I have a finction that displays a value on the label of
    WUC like

    Sub DisplayValue(value as String)
    Mylabel.text=value
    End Sub

    QUESTION:

    What code shoud I have in my web page to be able to call DisplayValue so as
    to display a value in the label.

    I current get the message:
    Line 1122: Dim stuff As New
    PORTAL.ManageGeneralNameSpace.CLASSWUC
    Line 1123: stuff.DisplayValue("test")
    Exception Details: System.NullReferenceException: Object reference not set
    to an instance of an object.

    Thanks
     
    Support, Mar 24, 2005
    #1
    1. Advertising

  2. Support

    Louis Yeung Guest

    Well, I am also green in this usercontrol world. I believe that you should be
    able to do so in Page_Init because the instance variable MANAGEGENERAL should
    be of class CLASSWUC. Therefore, MANAGEGENERAL.DisplayValue("xxx") is valid.

    I do not think "new CLASSWUC" is a good idea because this is a user control
    class. It is normally created via "LoadControl". I believe you want to get
    back the created CLASSWUC instance rather than using a new instance.

    ...Louis

    "Support" wrote:

    > in asp.net
    > If I have a web usercontrol WUC with code behind Class CLASSWUC
    > and I have a web page that loads the control
    >
    > Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
    > System.EventArgs) Handles MyBase.Init
    > MANAGEGENERAL = LoadControl("WUC.ascx")
    > MyPlaceholder.Controls.Add(MANAGEGENERAL)
    > InitializeComponent()
    > End Sub
    >
    > And if in CLASSWUC I have a finction that displays a value on the label of
    > WUC like
    >
    > Sub DisplayValue(value as String)
    > Mylabel.text=value
    > End Sub
    >
    > QUESTION:
    >
    > What code shoud I have in my web page to be able to call DisplayValue so as
    > to display a value in the label.
    >
    > I current get the message:
    > Line 1122: Dim stuff As New
    > PORTAL.ManageGeneralNameSpace.CLASSWUC
    > Line 1123: stuff.DisplayValue("test")
    > Exception Details: System.NullReferenceException: Object reference not set
    > to an instance of an object.
    >
    > Thanks
    >
    >
    >
     
    Louis Yeung, Apr 1, 2005
    #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. Micke Palm

    Reach another function in a usercontrol

    Micke Palm, May 4, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    415
    Micke Palm
    May 4, 2004
  2. Support
    Replies:
    2
    Views:
    631
    Support
    Mar 24, 2005
  3. Edwin Knoppert

    Public struct in usercontrol, can't reach items

    Edwin Knoppert, Dec 5, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    337
    Edwin Knoppert
    Dec 5, 2006
  4. Nagaraj
    Replies:
    1
    Views:
    892
    Lionel B
    Mar 1, 2007
  5. Support

    stuck: I cant reach usercontrol's class ..

    Support, Mar 24, 2005, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    135
    Support
    Mar 24, 2005
Loading...

Share This Page