472,986 Members | 2,748 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Web Controls/User Controls - Access Modifier

I am messing around with Web User Controls at present and (think) I have
discovered the following.

1.) The identifier for the control in the code behind must match the ID for
the control on the page.

2.) The identifier must be delcared with a minimum access of 'Protected' in
order to work.

If the above is indeed correct, then I have made the following assumptions
for which I would be grateful if someone who knows far more than I, could
either validate or correct for me.

1.) The assembly needs to set these objects when the page is loaded and
assumes that the ID is allways the same as the ID in the HTML. This is
different from Windows Forms, where the controls may be made private if
required as the objects are instantiated within the form and do not need to
be set from an external object.

2.) Because of 1.) Non private access modifier are required.

I hope I have understood this correctly; I look forward to being corrected
or otherwise.
Many Thanks - Mr Newbie . . .

Nov 19 '05 #1
3 1897
> 1.) The identifier for the control in the code behind must match the ID
for the control on the page.

2.) The identifier must be delcared with a minimum access of 'Protected'
in order to work.
Correct.
1.) The assembly needs to set these objects when the page is loaded and
assumes that the ID is allways the same as the ID in the HTML. This is
different from Windows Forms, where the controls may be made private if
required as the objects are instantiated within the form and do not need
to be set from an external object.

2.) Because of 1.) Non private access modifier are required.
No. Let me explain. ASP.Net 1.1 is a bit confusing because a Template is
actually a class definition, even though it doesn't look like one. This is
why you can include CodeBehind in a .aspx page, rather than necessarily
using the CodeBehind method. The CodeBehind method is more for the purpose
of separating the presentation layer into logical "sections," the visible
presentation layer, and the logic that drives the visible presentation
layer.

When using the CodeBehind model, therefore, the Page Template (class) (or
UserControl Template - both are Templated Controls), inherits the CodeBehind
class. Therefore, for the CodeBehind class to access or control Controls in
the Template class, the CodeBehind class must declare these instances, and
the declarations in the CodeBehind class must, naturally, match the usage of
these instances in the Template.

ASP.Net 2.0 introduces a new concept, "partial classes." A partial class is
a single class definition that spans multiple pages. In the 2.0 model, it is
not necessary to do this declaration in the CodeBehind because the Template
does not inherit the CodeBehind, but is, in fact, merged with the CodeBehind
to create a single class definition.

So, in summary, the CodeBehind is a class definition, and the Template is a
class definition. As they are 2 different class definitions, in order for
the CodeBehind to manipulate instances of Controls in the Template which
inherits it, the instances must be declared as members of the base
(CodeBehind) class for the Template.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
A watched clock never boils.

"Mr Newbie" <he**@now.com> wrote in message
news:ut*************@TK2MSFTNGP15.phx.gbl...I am messing around with Web User Controls at present and (think) I have
discovered the following.

1.) The identifier for the control in the code behind must match the ID
for the control on the page.

2.) The identifier must be delcared with a minimum access of 'Protected'
in order to work.

If the above is indeed correct, then I have made the following assumptions
for which I would be grateful if someone who knows far more than I, could
either validate or correct for me.

1.) The assembly needs to set these objects when the page is loaded and
assumes that the ID is allways the same as the ID in the HTML. This is
different from Windows Forms, where the controls may be made private if
required as the objects are instantiated within the form and do not need
to be set from an external object.

2.) Because of 1.) Non private access modifier are required.

I hope I have understood this correctly; I look forward to being corrected
or otherwise.
Many Thanks - Mr Newbie . . .


Nov 19 '05 #2
Ahhh Haaaa!!!

Code Behind Class
|
|
Web Page Class (aspx - inherits Code Behind)

I now see exactly how this works from reading your reply. This has been most
informative Kevin, so thanks for the explanation. This had me bugged until I
read your reply, but it all makes perfect sense now.

I hate not understanding things as fully as possible, because it only leads
to confusion when things go wrong and you need to fix them. Knowing the
whole picture sure makes diagnostics easier. It has also cleared up a
question I have had for a while regarding binding context statements.

I have had a little dabble with ASP.NET 2.0, and the partial classes also do
seem to make things a lot clearer from the developer perspective as one
doesent have all that designer code hanging around your own functional
code, which makes it look so busy ( esp with windows forms designer code ).

Thanks Again - Mr Newbie.




"Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> wrote in message
news:ur**************@tk2msftngp13.phx.gbl...
1.) The identifier for the control in the code behind must match the ID
for the control on the page.

2.) The identifier must be delcared with a minimum access of 'Protected'
in order to work.


Correct.
1.) The assembly needs to set these objects when the page is loaded and
assumes that the ID is allways the same as the ID in the HTML. This is
different from Windows Forms, where the controls may be made private if
required as the objects are instantiated within the form and do not need
to be set from an external object.

2.) Because of 1.) Non private access modifier are required.


No. Let me explain. ASP.Net 1.1 is a bit confusing because a Template is
actually a class definition, even though it doesn't look like one. This is
why you can include CodeBehind in a .aspx page, rather than necessarily
using the CodeBehind method. The CodeBehind method is more for the purpose
of separating the presentation layer into logical "sections," the visible
presentation layer, and the logic that drives the visible presentation
layer.

When using the CodeBehind model, therefore, the Page Template (class) (or
UserControl Template - both are Templated Controls), inherits the
CodeBehind class. Therefore, for the CodeBehind class to access or control
Controls in the Template class, the CodeBehind class must declare these
instances, and the declarations in the CodeBehind class must, naturally,
match the usage of these instances in the Template.

ASP.Net 2.0 introduces a new concept, "partial classes." A partial class
is a single class definition that spans multiple pages. In the 2.0 model,
it is not necessary to do this declaration in the CodeBehind because the
Template does not inherit the CodeBehind, but is, in fact, merged with the
CodeBehind to create a single class definition.

So, in summary, the CodeBehind is a class definition, and the Template is
a class definition. As they are 2 different class definitions, in order
for the CodeBehind to manipulate instances of Controls in the Template
which inherits it, the instances must be declared as members of the base
(CodeBehind) class for the Template.

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
A watched clock never boils.

"Mr Newbie" <he**@now.com> wrote in message
news:ut*************@TK2MSFTNGP15.phx.gbl...
I am messing around with Web User Controls at present and (think) I have
discovered the following.

1.) The identifier for the control in the code behind must match the ID
for the control on the page.

2.) The identifier must be delcared with a minimum access of 'Protected'
in order to work.

If the above is indeed correct, then I have made the following
assumptions for which I would be grateful if someone who knows far more
than I, could either validate or correct for me.

1.) The assembly needs to set these objects when the page is loaded and
assumes that the ID is allways the same as the ID in the HTML. This is
different from Windows Forms, where the controls may be made private if
required as the objects are instantiated within the form and do not need
to be set from an external object.

2.) Because of 1.) Non private access modifier are required.

I hope I have understood this correctly; I look forward to being
corrected or otherwise.
Many Thanks - Mr Newbie . . .



Nov 19 '05 #3
My pleasure.

Yes, partial classes do seem to me to be useful. I have seen them employed
quite effectively with Windows Forms templates. I haven't gotten into
ASP.Net 2.0 much yet, but I imagine they are just as helpful there.

Time will tell.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
A watched clock never boils.

"Mr Newbie" <he**@now.com> wrote in message
news:eb*************@TK2MSFTNGP09.phx.gbl...
Ahhh Haaaa!!!

Code Behind Class
|
|
Web Page Class (aspx - inherits Code Behind)

I now see exactly how this works from reading your reply. This has been
most informative Kevin, so thanks for the explanation. This had me bugged
until I read your reply, but it all makes perfect sense now.

I hate not understanding things as fully as possible, because it only
leads to confusion when things go wrong and you need to fix them. Knowing
the whole picture sure makes diagnostics easier. It has also cleared up a
question I have had for a while regarding binding context statements.

I have had a little dabble with ASP.NET 2.0, and the partial classes also
do seem to make things a lot clearer from the developer perspective as one
doesent have all that designer code hanging around your own functional
code, which makes it look so busy ( esp with windows forms designer
code ).

Thanks Again - Mr Newbie.




"Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> wrote in message
news:ur**************@tk2msftngp13.phx.gbl...
1.) The identifier for the control in the code behind must match the ID
for the control on the page.

2.) The identifier must be delcared with a minimum access of 'Protected'
in order to work.


Correct.
1.) The assembly needs to set these objects when the page is loaded and
assumes that the ID is allways the same as the ID in the HTML. This is
different from Windows Forms, where the controls may be made private if
required as the objects are instantiated within the form and do not need
to be set from an external object.

2.) Because of 1.) Non private access modifier are required.


No. Let me explain. ASP.Net 1.1 is a bit confusing because a Template is
actually a class definition, even though it doesn't look like one. This
is why you can include CodeBehind in a .aspx page, rather than
necessarily using the CodeBehind method. The CodeBehind method is more
for the purpose of separating the presentation layer into logical
"sections," the visible presentation layer, and the logic that drives the
visible presentation layer.

When using the CodeBehind model, therefore, the Page Template (class) (or
UserControl Template - both are Templated Controls), inherits the
CodeBehind class. Therefore, for the CodeBehind class to access or
control Controls in the Template class, the CodeBehind class must declare
these instances, and the declarations in the CodeBehind class must,
naturally, match the usage of these instances in the Template.

ASP.Net 2.0 introduces a new concept, "partial classes." A partial class
is a single class definition that spans multiple pages. In the 2.0 model,
it is not necessary to do this declaration in the CodeBehind because the
Template does not inherit the CodeBehind, but is, in fact, merged with
the CodeBehind to create a single class definition.

So, in summary, the CodeBehind is a class definition, and the Template is
a class definition. As they are 2 different class definitions, in order
for the CodeBehind to manipulate instances of Controls in the Template
which inherits it, the instances must be declared as members of the base
(CodeBehind) class for the Template.

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
A watched clock never boils.

"Mr Newbie" <he**@now.com> wrote in message
news:ut*************@TK2MSFTNGP15.phx.gbl...
I am messing around with Web User Controls at present and (think) I have
discovered the following.

1.) The identifier for the control in the code behind must match the ID
for the control on the page.

2.) The identifier must be delcared with a minimum access of 'Protected'
in order to work.

If the above is indeed correct, then I have made the following
assumptions for which I would be grateful if someone who knows far more
than I, could either validate or correct for me.

1.) The assembly needs to set these objects when the page is loaded and
assumes that the ID is allways the same as the ID in the HTML. This is
different from Windows Forms, where the controls may be made private if
required as the objects are instantiated within the form and do not need
to be set from an external object.

2.) Because of 1.) Non private access modifier are required.

I hope I have understood this correctly; I look forward to being
corrected or otherwise.
Many Thanks - Mr Newbie . . .




Nov 19 '05 #4

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

Similar topics

2
by: Dan Disney | last post by:
I have read conflicting information on the access scope of VB.Net class declarations when no access modifier is specified. MSDN library documentation states "Classes that do not specify an access...
3
by: N Khan via .NET 247 | last post by:
Hi, I know the usage of access modifier ?public? in DLL assembliesbut I am a bit puzzled that if let say I have a public class inan exe assembly then what purpose access modifier ?public?...
1
by: Ashkan Daie | last post by:
Hi All, Is there an internal access modifier in managed vc++ like vc#? Thanks, Ashkan
1
by: Mark Kamoski | last post by:
Hi-- Please help. What is the default access modifier value for a Sub or a Function when one has not explicitly been set. In MSDN, in "Access Types", it states... "If no access modifier...
1
by: Newbie | last post by:
Hi, I want to use an anchor in my control so that when I place it on a page it will always go to the top of the page. So on my Host page I put <a name="top" /> In my link on the control...
0
by: JohnyStyles | last post by:
I have a templated user control which looks like this: ----------------------------------------------------------------- <uc:MyUserControl runat=server> <TemplateProperty> </TemplateProperty>...
11
by: Web Search Store | last post by:
Hello, I set up a web page with 2 user controls. In classic asp, the first one did all the declarations, and the second one used the values, and could reset it. In ASP.Net so far I can't...
2
by: San24 | last post by:
Guys, Let me explain the application I have - Form > Main Tab Control > Main Tab Page > User Control > Sub Tab Control > Sub Tab Page > User Control > Contols/Text Box. Form - The main...
0
Aimee Bailey
by: Aimee Bailey | last post by:
Hi, i've come accross a problem, and to be honest im not exactly sure how to google keyword the solution, so i thought id post the situation in here. I am building a new usercontrol that relies on...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...
3
SueHopson
by: SueHopson | last post by:
Hi All, I'm trying to create a single code (run off a button that calls the Private Sub) for our parts list report that will allow the user to filter by either/both PartVendor and PartType. On...

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.