473,385 Members | 1,645 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,385 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 1920
> 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: 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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.