By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,894 Members | 1,937 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,894 IT Pros & Developers. It's quick & easy.

controls sometimes private & sometimes protected

P: n/a
When you add a control to a form in a windows application , It will be
private by default
but
in a web application it will be protected by default , as well as , it can
be changed to private .

WHY ???
Sep 21 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hadidi,

This is because in in the case of Windows Forms the VS generates the class
of the form or control as it is going to be used by the application. They
are accessible from the form's or controls own code.
In ASP.NET form thought, the class that you design in VS is used as a base
class for a new class generated by ASP.NET compiler when the page is
compiled to be served to the web browser. This new class has code to build
the page structure and thus the control cariable needs to be assesbile by
this derived class in order to be initialized. This is the reason why the
variable needs to be protected.
--
HTH
Stoitcho Goutsev (100)
"Hadidi" <Ha****@discussions.microsoft.comwrote in message
news:8B**********************************@microsof t.com...
When you add a control to a form in a windows application , It will be
private by default
but
in a web application it will be protected by default , as well as , it can
be changed to private .

WHY ???

Sep 21 '06 #2

P: n/a
Hadidi <Ha****@discussions.microsoft.comwrote:
When you add a control to a form in a windows application , It will be
private by default
but
in a web application it will be protected by default , as well as , it can
be changed to private .

WHY ???
In a web application, from what I remember (and it may have changed in
ASP.NET 2.0 where partial classes could solve the problem more
elegantly) the code-behind forms the base class, and the aspx code
creates a class deriving from that class. The aspx code may well need
to access the controls, which is why they're protected.

At least, that's my guess :)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Sep 21 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.