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

T

theintrepidfox

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
 
E

Erik Funkenbusch

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?
 
T

theintrepidfox

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top