473,320 Members | 1,991 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

call asp.net from user control

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???
Nov 18 '05 #1
4 1078
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?

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

On Fri, 26 Nov 2004 09:26:57 -0800,
<an*******@discussions.microsoft.com> wrote:
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???


Nov 18 '05 #2
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....

-----Original Message-----
When you have <class name>.<func> you are trying to call a functionthrough the name of the class. There can be multiple instances of<class name> floating around in memory, the compiler doesn't knowwhich 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?

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

On Fri, 26 Nov 2004 09:26:57 -0800,
<an*******@discussions.microsoft.com> wrote:
when i write in my user control <asp.net class name>.<nameof 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 theasp.net page> it works fine. can someone please explain
WHY???


.

Nov 18 '05 #3
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/

On Fri, 26 Nov 2004 10:01:30 -0800,
<an*******@discussions.microsoft.com> wrote:
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....


Nov 18 '05 #4
great! thanks for you time Scott.
-----Original Message-----
Yes, try to read up on object oriented programming. I don't know whatthe hottest books are for OOP beginners these days, but I did a quicksearch and everything I found looked sucky.

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

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 thepedal to the metal" / "drop the hammer" / "gun it" depending on whatslang term you prefer.

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

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

On Fri, 26 Nov 2004 10:01:30 -0800,
<an*******@discussions.microsoft.com> wrote:
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. whatcan be more clear then "cls.func1"? especially when cls1
is public! i guess it's this oop that i have to get used
to....


.

Nov 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: John | last post by:
Hi all, This really is quite an urgent matter. I have a page with multiple, dynamically-loaded user controls and when a user clicks on a button, the whole form is submitted. Now at this stage...
7
by: Max | last post by:
How do I declare in the parent page's code behind a user control? I want to call a sub that is located in the user control. Want to do something like this: Call MyUserControl.MySub()
1
by: moondaddy | last post by:
I need to replace a user control on a page with a different user control. The challenge I'm faced with is that this call is being made from the user control being replaced. Normally I replace...
1
by: Kris van der Mast | last post by:
Hi, been a while since I posted a question myself instead of trying to help others out. I'm refactoring an existing web app that uses dynamic loading of user controls and a lot of...
1
by: Ed Chiu | last post by:
Hi, I createed a user control named fnCalender.ascx, there is a method called getInfo defined in calender.ascx. I drag and drop this control into a web form then I tried to call the method...
6
by: grist2mill | last post by:
I want to create a standard tool bar that appears on all pages that is a control. The toolbar has a button 'New'. What I wolud like when the user clicks on 'New' depends on the page they are on. I...
4
by: Tim::.. | last post by:
Can someone please help.... I'm having major issues with a user control I'm tring to create! I an trying to execute a sub called UploadData() from a user control which I managed to do but for...
2
by: Tim::.. | last post by:
Can someone please help.... I'm having major issues with a user control I'm tring to create! I an trying to execute a sub called UploadData() from a user control which I managed to do but for...
3
by: Tim::.. | last post by:
Can someone please help.... I'm having major issues with a user control I'm tring to create! I an trying to execute a sub called UploadData() from a user control which I managed to do but for...
4
by: bill | last post by:
I have a Repeater control in a web user control. The web user control has a public method named PopulateRepeater which takes an ID as an parameter and populates the repeater control based on the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.