Skip to main content
edited body
Source Link
S Nash
  • 2.5k
  • 3
  • 38
  • 68

Here is the issue:

I have a simple ASP.NET form with 2 buttons.

One of them is created by dragging the button from the tools and the other I created directly in HTML:

<body>
<form id="Form1" method="post" runat="server">
    <asp:Button OnClick="ABC" Runat="server" Text="rrr" id="Button1"></asp:Button>
    <asp:Button  id="Button2" runat="server" Text="Button"></asp:Button>
</form>
</body>

Button2 is created using tools and has the following Event Handler:

 Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim s As String = ""
 End Sub

This "Private Event handler runs without any problem.

However for the button whichi swhich is created under HTML , we have the following event handler:

Private Sub ABC(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim a As Integer = 0

End Sub

For this one iI get the following complile error:

Compiler Error Message: BC30390: 'WebApplication9.WebForm1.Private Sub ABC(sender As Object, e As System.EventArgs)' is not accessible in this context because it is 'Private'.

If I chacgechange the event handler scope from Private to protected this will work. Question is why private works for one event handler but not the other one.

Here is the issue:

I have a simple ASP.NET form with 2 buttons.

One of them is created by dragging the button from the tools and the other I created directly in HTML:

<body>
<form id="Form1" method="post" runat="server">
    <asp:Button OnClick="ABC" Runat="server" Text="rrr" id="Button1"></asp:Button>
    <asp:Button  id="Button2" runat="server" Text="Button"></asp:Button>
</form>
</body>

Button2 is created using tools and has the following Event Handler:

 Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim s As String = ""
 End Sub

This "Private Event handler runs without any problem.

However for the button whichi s created under HTML , we have the following event handler:

Private Sub ABC(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim a As Integer = 0

End Sub

For this one i get the following complile error:

Compiler Error Message: BC30390: 'WebApplication9.WebForm1.Private Sub ABC(sender As Object, e As System.EventArgs)' is not accessible in this context because it is 'Private'.

If I chacge the event handler scope from Private to protected this will work. Question is why private works for one event handler but not the other one.

Here is the issue:

I have a simple ASP.NET form with 2 buttons.

One of them is created by dragging the button from the tools and the other I created directly in HTML:

<body>
<form id="Form1" method="post" runat="server">
    <asp:Button OnClick="ABC" Runat="server" Text="rrr" id="Button1"></asp:Button>
    <asp:Button  id="Button2" runat="server" Text="Button"></asp:Button>
</form>
</body>

Button2 is created using tools and has the following Event Handler:

 Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim s As String = ""
 End Sub

This "Private Event handler runs without any problem.

However for the button which is created under HTML , we have the following event handler:

Private Sub ABC(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim a As Integer = 0

End Sub

For this one I get the following complile error:

Compiler Error Message: BC30390: 'WebApplication9.WebForm1.Private Sub ABC(sender As Object, e As System.EventArgs)' is not accessible in this context because it is 'Private'.

If I change the event handler scope from Private to protected this will work. Question is why private works for one event handler but not the other one.

removed C# tag, and added vb
Link
Jens Kloster
  • 11.2k
  • 5
  • 42
  • 55
Source Link
S Nash
  • 2.5k
  • 3
  • 38
  • 68

Why a private event handler does not work in ASP.NET

Here is the issue:

I have a simple ASP.NET form with 2 buttons.

One of them is created by dragging the button from the tools and the other I created directly in HTML:

<body>
<form id="Form1" method="post" runat="server">
    <asp:Button OnClick="ABC" Runat="server" Text="rrr" id="Button1"></asp:Button>
    <asp:Button  id="Button2" runat="server" Text="Button"></asp:Button>
</form>
</body>

Button2 is created using tools and has the following Event Handler:

 Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim s As String = ""
 End Sub

This "Private Event handler runs without any problem.

However for the button whichi s created under HTML , we have the following event handler:

Private Sub ABC(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim a As Integer = 0

End Sub

For this one i get the following complile error:

Compiler Error Message: BC30390: 'WebApplication9.WebForm1.Private Sub ABC(sender As Object, e As System.EventArgs)' is not accessible in this context because it is 'Private'.

If I chacge the event handler scope from Private to protected this will work. Question is why private works for one event handler but not the other one.