call asp.net from user control

G

Guest

when i write in my user control <asp.net class name>.<name
of function in the asp.net page> i get compilation error
(Reference to a non-shared member requires an object
reference) and when i write
ctype(page,<asp.net class name>).<name of function in the
asp.net page> it works fine. can someone please explain
WHY???
 
S

Scott Allen

When you have <class name>.<func> you are trying to call a function
through the name of the class. There can be multiple instances of
<class name> floating around in memory, the compiler doesn't know
which object (page) you want the method called on.

In ctype(page,<class name>).<func> you are saying

1: Take a specific object that I am referencing.

2: Treat the reference as if refering to an instance of <class name>
instead of just refering to a Page.

3: Invoke func on the object.

Making any more sense?
 
G

Guest

not realy. i'm sure what you're saying is right i just
can't understand why do i have to use this ctype....i
mean - i'm working on a specific solution, with only 1
object called "cls1" and this is my aspx class name. what
can be more clear then "cls.func1"? especially when cls1
is public! i guess it's this oop that i have to get used
to....
 
S

Scott Allen

Yes, try to read up on object oriented programming. I don't know what
the hottest books are for OOP beginners these days, but I did a quick
search and everything I found looked sucky.

One of the first steps is to distinguish between a class and an
object.

An example of a class might be Ford. Ford describes a type of car.
Saying cls.func1 is similar to saying

Ford.Accelerate().

It doesn't make much sense because you can't accelerate a type of car,
you have to accelerate a car object.

Dim myCar as New Ford
myCar.Accelerate()

Now I've created an instance of the car, and I'm going to "put the
pedal to the metal" / "drop the hammer" / "gun it" depending on what
slang term you prefer.

In your case you already have an instance available that ASP.NET
created, and the Page variable refers to it. It's just that you have
to give the compiler a little more information about the reference.
You'll lean about this if you read about inheritance and polymorphism
in OOP texts.
 
G

Guest

great! thanks for you time Scott.
-----Original Message-----
Yes, try to read up on object oriented programming. I don't know what
the hottest books are for OOP beginners these days, but I did a quick
search and everything I found looked sucky.

One of the first steps is to distinguish between a class and an
object.

An example of a class might be Ford. Ford describes a type of car.
Saying cls.func1 is similar to saying

Ford.Accelerate().

It doesn't make much sense because you can't accelerate a type of car,
you have to accelerate a car object.

Dim myCar as New Ford
myCar.Accelerate()

Now I've created an instance of the car, and I'm going to "put the
pedal to the metal" / "drop the hammer" / "gun it" depending on what
slang term you prefer.

In your case you already have an instance available that ASP.NET
created, and the Page variable refers to it. It's just that you have
to give the compiler a little more information about the reference.
You'll lean about this if you read about inheritance and polymorphism
in OOP texts.

--
Scott
http://www.OdeToCode.com/blogs/scott/



.
 

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

Top