473,289 Members | 1,923 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,289 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 1914
> 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...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
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: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
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: 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)...

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.