Coming out of the closet - Object Reference - Knowing I most likely won't get an answer...

Discussion in 'ASP .Net' started by theintrepidfox@hotmail.com, Mar 24, 2006.

  1. Guest

    Hi Everyone

    Here's a really simple and fundamental question for you boys and girls.
    I'm quite embarrased asking it actually as I've ben programming for
    four years now, always working my way around the issue, but thought of
    finally coming out of the closet.

    Question:
    How do I manipulate (reference) an object on a form (.aspx) in ASP.NET
    2.0 from a class? There are articles on how pass values between forms
    etc etc but I really never figured that out which is really bad I
    guess!

    Sample:
    I've a page called default.aspx with a ASP.NET 2.0 label control
    And I've a class in the App_Code folder called clsLabel.vb

    In the code-beside of default.aspx I'd like to put something like:
    ....
    Label1.text = clsLabel.SetText()
    ....

    While I've a Sub in clsLabel that sets the label text.
    ....
    Label1.text = "Hello"
    ....

    Note that this is a simple example and
    I'd be grateful if you can please explain in plain English and
    idiot-proof way.
    Thank you for your help, infinite wisdom and efforts!

    Martin
    , Mar 24, 2006
    #1
    1. Advertising

  2. On 24 Mar 2006 15:45:28 -0800, wrote:

    > Question:
    > How do I manipulate (reference) an object on a form (.aspx) in ASP.NET
    > 2.0 from a class? There are articles on how pass values between forms
    > etc etc but I really never figured that out which is really bad I
    > guess!


    I think your premise is flawed. You shouldn't be trying to manipulate a
    form from a middle tier class. That's the entire point of middle tier, to
    seperate logic from presentation.

    A form should call into your object to get it's data. The data should not
    call into the form. Get the picture?
    Erik Funkenbusch, Mar 25, 2006
    #2
    1. Advertising

  3. Guest

    Thanks for your advice and thoughts Erik

    Yes, that makes sense and admit that I actually have explained it
    incorrectly.
    The form calls indeed the class not the other way round. My intention
    has been lost in simplifiying the issue.
    What I really trying to do is have my form call a function in my class
    and then return an object.
    It's working know. Hope it's good practice the way I do it though?
    Thank you very much for your time and efforts and for pointing me in
    the right direction!

    In aspx:

    Dim clsFraMenu As New clsFraMenu
    mnuLanguage = clsFraMenu.GetMnuLanguage(mnuLanguage)

    In class:

    Public Function GetMnuLanguage(ByVal objmnuLanguage As Menu) As Menu

    Dim mnuLanguage As Menu = objmnuLanguage
    ....
    Add menu items
    ....

    Return mnuLanguage

    End Function
    , Mar 25, 2006
    #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. Ken Guest
    Replies:
    2
    Views:
    272
    Ken Guest
    Jan 6, 2006
  2. Sune
    Replies:
    10
    Views:
    555
    Martin Ambuhl
    Oct 7, 2005
  3. AAaron123
    Replies:
    2
    Views:
    2,081
    AAaron123
    Jan 16, 2009
  4. Adam Cohen
    Replies:
    1
    Views:
    121
    Greg Willits
    Jun 14, 2010
  5. Ziliang Chen
    Replies:
    3
    Views:
    138
    Ziliang Chen
    Feb 22, 2013
Loading...

Share This Page