Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / October 2005

Tip: Looking for answers? Try searching our database.

Web Controls/User Controls - Access Modifier

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mr Newbie - 31 Oct 2005 11:05 GMT
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 . . .
Kevin Spencer - 31 Oct 2005 14:06 GMT
> 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
[quoted text clipped - 3 lines]
>
> 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.

Signature

HTH,

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

>I am messing around with Web User Controls at present and (think) I have
>discovered the following.
[quoted text clipped - 21 lines]
>
> Many Thanks - Mr Newbie . . .
Mr Newbie - 31 Oct 2005 14:37 GMT
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.

>> 1.) The identifier for the control in the code behind must match the ID
>> for the control on the page.
[quoted text clipped - 64 lines]
>>
>> Many Thanks - Mr Newbie . . .
Kevin Spencer - 31 Oct 2005 17:01 GMT
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.

Signature

HTH,

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

> Ahhh Haaaa!!!
>
[quoted text clipped - 88 lines]
>>>
>>> Many Thanks - Mr Newbie . . .

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.