Private code-behind methods ignored by the compiler - ASP.NET

When declaring a code method as private (for example, an event handler), the compiler ignores it and produces:

"Compiler error message: CS1061:" ASP.default_aspx "does not contain a definition for" OnLoginUser ", and the extension method" OnLoginUser "cannot be found that accepts the first argument of type" ASP.default_aspx "(you do not see using the directive or link to assembly?) "

In practice, OnLoginUsed exists, and when the identifier is changed to "public \ protected", everything works fine.

The question is, why is it impossible to declare such a method private? after all, it is called internally by other members of the class.

10x!

+3
source share
1 answer

Your ASPX page does not match your code per page. He inherits it, and therefore he cannot see private members. That is why they must be protected or open.

+9
source

Source: https://habr.com/ru/post/1718827/


All Articles