Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net (http://www.velocityreviews.com/forums/f29-asp-net.html)
-   -   Procedure not accessible when private in webform (http://www.velocityreviews.com/forums/t77855-procedure-not-accessible-when-private-in-webform.html)

Tim Zych 05-11-2004 03:13 PM

Procedure not accessible when private in webform
 
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



Kevin Spencer 05-11-2004 03:25 PM

Re: Procedure not accessible when private in webform
 
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.

"Tim Zych" <tzych@earth_noworms_link_dotttt.net> wrote in message
news:#ZiwKq2NEHA.3596@tk2msftngp13.phx.gbl...
> 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
>
>




Scott Mitchell [MVP] 05-11-2004 03:31 PM

Re: Procedure not accessible when private in webform
 
> 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/de...bjectmodel.asp

Happy Programming!

--

Scott Mitchell
mitchell@4guysfromrolla.com
http://www.4GuysFromRolla.com
http://www.ASPFAQs.com
http://www.ASPMessageboard.com

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

Tim Zych 05-12-2004 02:40 AM

Re: Procedure not accessible when private in webform
 
Thank you Kevin and Scott.
Tim

"Tim Zych" <tzych@earth_noworms_link_dotttt.net> wrote in message
news:#ZiwKq2NEHA.3596@tk2msftngp13.phx.gbl...
> 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
>
>





All times are GMT. The time now is 05:25 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.