By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,466 Members | 1,309 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,466 IT Pros & Developers. It's quick & easy.

Procedure not accessible when private in webform

P: n/a
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
Nov 18 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
> 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
mi******@4guysfromrolla.com
http://www.4GuysFromRolla.com
http://www.ASPFAQs.com
http://www.ASPMessageboard.com

* When you think ASP, think 4GuysFromRolla.com!
Nov 18 '05 #2

P: n/a
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:#Z**************@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

Nov 18 '05 #3

P: n/a
Thank you Kevin and Scott.
Tim

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

Nov 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.