Procedure not accessible when private in webform

Discussion in 'ASP .Net' started by Tim Zych, May 11, 2004.

  1. Tim Zych

    Tim Zych Guest

    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
    Tim Zych, May 11, 2004
    #1
    1. Advertising

  2. 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
    >
    >
    Kevin Spencer, May 11, 2004
    #2
    1. Advertising

  3. > 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

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

    * When you think ASP, think 4GuysFromRolla.com!
    Scott Mitchell [MVP], May 11, 2004
    #3
  4. Tim Zych

    Tim Zych Guest

    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
    >
    >
    Tim Zych, May 12, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jack Wright
    Replies:
    3
    Views:
    1,615
    Chris Jackson
    Jan 5, 2004
  2. Richard
    Replies:
    1
    Views:
    1,771
    Steven Cheng[MSFT]
    Jul 27, 2004
  3. Siam
    Replies:
    6
    Views:
    353
    Daniel T.
    Aug 1, 2006
  4. Pavel
    Replies:
    2
    Views:
    409
    Pavel
    May 1, 2011
  5. Frank Meyer

    Private methods not so private?

    Frank Meyer, Aug 1, 2007, in forum: Ruby
    Replies:
    14
    Views:
    235
Loading...

Share This Page