Something I have never thought too hard about but I am curiuos and want to understand the actual reasoning. In ASP.NET using VB.NET, you can define the wired up button click event (to an ASP.NET server control) in 2 different ways (for the purpose of this conversation - manually wiring up via button property not in question here):
I understand the difference between Private and Protected; that is not in question here. I just want to know the actual reason (not guessing or speculating please) of why based on how the wired up event is autocreated it generates a different Access Level on the method?
Thanks!
The reason it's protected when declared in the control itself is the the .aspx is compiled to a class on the fly that inherits from the codebehind, so it wouldn't see the method if it was private. When the event is assigned internally to the codebehind, obviously the private member is accessible.
Both are valid approaches, just depends on how you want to skin the cat, and if a control is dynamically created, you may have to assign the event in the codebehind, so that mechanism needs to be there.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With