Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Procedure not accessible when private in webform

Reply
Thread Tools

Procedure not accessible when private in webform

 
 
Tim Zych
Guest
Posts: n/a
 
      05-11-2004
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


 
Reply With Quote
 
 
 
 
Kevin Spencer
Guest
Posts: n/a
 
      05-11-2004
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:#...
> 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
>
>



 
Reply With Quote
 
 
 
 
Scott Mitchell [MVP]
Guest
Posts: n/a
 
      05-11-2004
> 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

http://www.4GuysFromRolla.com
http://www.ASPFAQs.com
http://www.ASPMessageboard.com

* When you think ASP, think 4GuysFromRolla.com!
 
Reply With Quote
 
Tim Zych
Guest
Posts: n/a
 
      05-12-2004
Thank you Kevin and Scott.
Tim

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



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Why internal struct template is accessible even if private? Pavel C++ 2 05-01-2011 08:42 PM
Private methods not so private? Frank Meyer Ruby 14 08-02-2007 07:29 PM
Private member accessible from another object? Siam C++ 6 08-01-2006 08:50 PM
Error When using Crystal Reports: 'C' is not accessible in this context because it is 'Private'. Richard ASP .Net 1 07-27-2004 07:03 AM
ProcessModelConfig' is not accessible in this context because it is 'Private' Jack Wright ASP .Net 3 01-05-2004 03:58 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57