stuck: I cant reach usercontrol's class ..

Discussion in 'ASP .Net' 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

    Karl Seguin Guest

    private manageGeneral as ClassWuc
    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles MyBase.Init
    manageGeneral = ctype(LoadControl("WUC.ascx"), ClassWuc)
    manageGeneral.DisplayValue("heh")
    MyPlaceholder.Controls.Add(manageGeneral )
    InitializeComponent()
    End Sub

    you cold call displayValue in page_load as well...the trick is that
    Page.LoadControl returns a System.Web.UI.Control...which your class ClassWuc
    inherits from...however, in order to get DisplayValue (which
    System.Web.UI.control doesn't have) you need to cast the returned type to
    the appropriate ClassWuc class

    Karl


    --
    MY ASP.Net tutorials
    http://www.openmymind.net/ - New and Improved (yes, the popup is
    annoying)
    http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
    come!)
    "Support" <> wrote in message
    news:...
    > 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
    >
    >
    >
     
    Karl Seguin, Mar 24, 2005
    #2
    1. Advertising

  3. Support

    Support Guest

    THANKS!!!
    saved from desperation..

    "Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
    wrote in message news:%...
    > private manageGeneral as ClassWuc
    > Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
    > System.EventArgs) Handles MyBase.Init
    > manageGeneral = ctype(LoadControl("WUC.ascx"), ClassWuc)
    > manageGeneral.DisplayValue("heh")
    > MyPlaceholder.Controls.Add(manageGeneral )
    > InitializeComponent()
    > End Sub
    >
    > you cold call displayValue in page_load as well...the trick is that
    > Page.LoadControl returns a System.Web.UI.Control...which your class
    > ClassWuc
    > inherits from...however, in order to get DisplayValue (which
    > System.Web.UI.control doesn't have) you need to cast the returned type to
    > the appropriate ClassWuc class
    >
    > Karl
    >
    >
    > --
    > MY ASP.Net tutorials
    > http://www.openmymind.net/ - New and Improved (yes, the popup is
    > annoying)
    > http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
    > come!)
    > "Support" <> wrote in message
    > news:...
    >> 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
    #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. Micke Palm

    Reach another function in a usercontrol

    Micke Palm, May 4, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    428
    Micke Palm
    May 4, 2004
  2. Edwin Knoppert

    Public struct in usercontrol, can't reach items

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

    stuck: I cant reach usercontrol's class ..

    Support, Mar 24, 2005, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    143
    Louis Yeung
    Apr 1, 2005
  5. Support

    stuck: I cant reach usercontrol's class ..

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

Share This Page