Procedure not accessible when private in webform

  • Thread starter Thread starter Tim Zych
  • Start date Start date
T

Tim Zych

If I declare a procedure in a webform as Public and attach it to a button in
the same webform, it runs fine. If I change it to Private Sub and try to
click it i get the error:

'codelib.editcode.Private Sub SaveRecord(sender As Object, e As
System.EventArgs)' is not accessible in this context because it is
'Private'.

What am I doing wrong? Everything is in one webform.

Private worked in my notepad version of the project. Why is it not working
in my vsnet version?

Thanks
 
If you're using a CodeBehind class, the Page Template inherits it, which
means that Private CodeBehind members will not be accessible to the Page
Template. Make it Protected instead.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
If I declare a procedure in a webform as Public and attach it to a button in
the same webform, it runs fine. If I change it to Private Sub and try to
click it i get the error:

'codelib.editcode.Private Sub SaveRecord(sender As Object, e As
System.EventArgs)' is not accessible in this context because it is
'Private'.

What am I doing wrong? Everything is in one webform.

When the ASP.NET Web page is visited, it is turned into a class that is
*DERIVED* from the code-behind class (which is, in turn, inherited from
the System.Web.UI.Page class). So, the code-behind class becomes a base
class for the actual class that is executed. Inheritence, as you may
know, keeps private members private, but protected and public members
inherit through. So your event handlers need to be protected or public
when using the code-behind model.
Private worked in my notepad version of the project. Why is it not working
in my vsnet version?

In the model where you have the code in a server-side script block, the
class autogenerated is derived directly from the Page class, with the
methods in the server-side script block embedded directly in the
autogenerated class. So they can be private.

For more information, see:

The ASP.NET Page Object Model
http://msdn.microsoft.com/library/d.../en-us/dnaspp/html/aspnet-pageobjectmodel.asp

Happy Programming!

--

Scott Mitchell
(e-mail address removed)
http://www.4GuysFromRolla.com
http://www.ASPFAQs.com
http://www.ASPMessageboard.com

* When you think ASP, think 4GuysFromRolla.com!
 
Back
Top