473,803 Members | 4,591 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

scope of private vs protected objects

A label on an ascx control has a corresponding declaration in the c#
code-behind page.
I was curious what would happen if I made that declaration 'PRIVATE' instead
of 'PROTECTED'.
The only things that touch that label are functions in that code-behind page
itself -- nothing on the outside.

Basically, it doesn't work. Only when I changed it back to 'protected' in
the ascx's cs page, could I modify the text in the label, from within
functions in that cs page. I was curious why this is.

I always thought 'Private' means that "anything on that class can access the
private / protected object".

TY for the explanation
Nov 16 '05 #1
4 11111
"Jason Shohet" <__******@yahoo .com> wrote in
news:eG******** *****@tk2msftng p13.phx.gbl:
A label on an ascx control has a corresponding declaration in
the c# code-behind page.
I was curious what would happen if I made that declaration
'PRIVATE' instead of 'PROTECTED'.
The only things that touch that label are functions in that
code-behind page itself -- nothing on the outside.

Basically, it doesn't work. Only when I changed it back to
'protected' in the ascx's cs page, could I modify the text in
the label, from within functions in that cs page. I was curious
why this is.

I always thought 'Private' means that "anything on that class
can access the private / protected object".


Jason,

There are two classes in an .aspx page: the abstract parent class
(in the code-behind file), and the concrete child class (in the .aspx
file).

The members of the abstract class in the code-behind file need to
have a protected scope so they will be visible when .Net creates an
instance of the .aspx page concrete child class.

See MSDN for more info:

http://msdn.microsoft.com/library/de...l=/library/en-
us/vbcon/html/vbconwebformsco demodel.asp

or

http://tinyurl.com/k82i
Hope this helps.

Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/
Nov 16 '05 #2
The page class that's actually instantiated is a subclass of the code-behind
class, so private members aren't accessable.

--
Mickey Williams
Author, "Microsoft Visual C# .NET Core Reference", MS Press
www.servergeek.com


"Jason Shohet" <__******@yahoo .com> wrote in message
news:eG******** *****@tk2msftng p13.phx.gbl...
A label on an ascx control has a corresponding declaration in the c#
code-behind page.
I was curious what would happen if I made that declaration 'PRIVATE' instead of 'PROTECTED'.
The only things that touch that label are functions in that code-behind page itself -- nothing on the outside.

Basically, it doesn't work. Only when I changed it back to 'protected' in
the ascx's cs page, could I modify the text in the label, from within
functions in that cs page. I was curious why this is.

I always thought 'Private' means that "anything on that class can access the private / protected object".

TY for the explanation

Nov 16 '05 #3

currently as of ASP.NET 1.1, the .aspx file is parsed upon request, and a new class is generated inheriting from your code behind class. so visibility of inheritance rules apply here. anything in your codebehind base class that you wish the child (.aspx) class to see and display needs to be protected. now with new partial class feature in C# 2.0, this should change. you shall be able to declare them as private in 2005

----- Jason Shohet wrote: ----

A label on an ascx control has a corresponding declaration in the c
code-behind page
I was curious what would happen if I made that declaration 'PRIVATE' instea
of 'PROTECTED'
The only things that touch that label are functions in that code-behind pag
itself -- nothing on the outside

Basically, it doesn't work. Only when I changed it back to 'protected' i
the ascx's cs page, could I modify the text in the label, from withi
functions in that cs page. I was curious why this is

I always thought 'Private' means that "anything on that class can access th
private / protected object"

TY for the explanatio

Nov 16 '05 #4
Thanks guys.
This new partial class feature sounds very cool. We have to wait until
2005... I wonder if there's a beta of the next .NET version out there
somewhere.
Nov 16 '05 #5

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

Similar topics

12
2681
by: Manolis | last post by:
Hi, I was wondering if there is any way to make two objects of the same class to be able to access each other's private data, like this: class A { public: void access( const A& a ) {cout<<"a.value="<<a.value<<endl; } private: int value;
4
2419
by: Marc Tanner | last post by:
Hello, I am currently working on a eventhandling system or something similar, and have the problem of loosing scope. I have read many interesting posts on this group and the faq article about closure, but it seems that i have still not understood everything. Below is my attempt to preserve the scope but it's not really nice and i think with the use of closure could it be done better. But at the moment i am quite confused and hope that...
4
1129
by: Ferret Face | last post by:
Hello, Folks! I have a large number of web object appearing on the same page so I decided to break them down into a number of panels with some control buttons like "Prev" and "Next" to make the appropriate panel visible. To help accoplish this I assign the panels to a panel array. Well I'm getting "Object reference not set to an instance of an object." as an error message causing me to go, "WTF!?" Can anyone shed some light on this...
9
1884
by: olanglois | last post by:
Hi, I am not sure if I have found a compiler bug (I am using VC++.NET2003) or if this is the correct behavior defined by the language but I am sure someone can clear up my confusion. Suppose the following: class Base { protected: int x;
7
2118
by: WXS | last post by:
Vote for this idea if you like it here: http://lab.msdn.microsoft.com/productfeedback/viewfeedback.aspx?feedbackid=5fee280d-085e-4fe2-af35-254fbbe96ee9 ----------------------------------------------------------------------------- This is a consortium of ideas from another thread on topic ----------------------------------------------------------------------------- One of the big issues of organizing items within a class, is there are many...
26
2153
by: Patient Guy | last post by:
The code below shows the familiar way of restricting a function to be a method of a constructed object: function aConstructor(arg) { if (typeof(arg) == "undefined") return (null); this.property1 = arg; this.property2 = aConstantDefinedGlobally; this.method1 = function (anArg) {
1
25703
pbmods
by: pbmods | last post by:
VARIABLE SCOPE IN JAVASCRIPT LEVEL: BEGINNER/INTERMEDIATE (INTERMEDIATE STUFF IN ) PREREQS: VARIABLES First off, what the heck is 'scope' (the kind that doesn't help kill the germs that cause bad breath)? Scope describes the context in which a variable can be used. For example, if a variable's scope is a certain function, then that variable can only be used in that function. If you were to try to access that variable anywhere else in...
0
2049
by: zman77 | last post by:
EDIT: -- forgot to mention... I am using Visual Studio 2005, on Win XP, on an intel machine Hi. This is my first post, though I've "lurked" for a while because I find these forums very helpful. Ok my problem is the following. I have a class that contains a "MakeByteArray" function. I have many objects of that class. Inside that function, I have a private variable, that is NOT static. It seems that when I put all these objects in...
2
1609
by: agendum97 | last post by:
Is there a way of constructing a "class" in JavaScript to access a private member of a different scope of the same type? It is important that the variable remain private, and not accessible in anyway publically. For example: function SomeObj(privateKey) { this.process = function(someObj) { if (!(someObj instanceof SomeObj))
0
9703
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10316
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10295
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10069
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7604
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6842
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5629
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4275
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2970
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.