Cannot access non-static member on type usercontrol from parent page or usercontrol

Turbo Pascal coder here. It’s been a long ride.

Updating from Oxy version-o-saurus and VS 2015 to latest and VS 2022.

Have usercontrols with this type declaration syntax:

ucListAndTaskControl = public partial class(System.Web.UI.UserControl)
method Page_Load(sender: Object; e: EventArgs);
method Page_PreRender(sender: Object; e:EventArgs);
method initialize;

Used to be all I had to do to make the a method accessible from the parent codebehind is to make it public. Then I could call ucListAndTaskControl.Initialize from its parent (the usercontrol ID is the same as the type unless I have to juggle two on a page which is rare).

Apparently this has become wrong or lazy or not thread-safe or something. Compiler throws error

|Error||(E642) Cannot access non-static member initialize on type ucListAndTaskControl

What is the proper syntax, or perhaps a property setting that I have failed to set?

D’oh. key there was the usercontrol element and the type had the same name. I had to rebuild this page and the automarkup changed the element name to ucListAndTaskControl1 and so the compiler thought my code referred to the type and not the element. Paranoia. I’m always paranoid that there’s some huge difference in the code when I upgrade this much.

1 Like

Hmm, a local member should have precedence over a type of the same name…

They weren’t the same name, though, that’s the problem. The auto markup had changed the name of the local member to xyz1 but it’s type was still xyz, so the compiler was treating my references to xyz as the type. When I renamed the user controls to xyz then that returned the universe to its proper alignment. However in my defense that whole process of having to cut and past code into empty pages was caused by an internal error E0 that gave me zero clue what was throwing it so I had to rebuild my projects page by page and then method by method to find the issue. The classic it’s broke error. I found the line of code this morning and I’m documenting it, then I’ll try to find a work around and then report it.

1 Like

I’d love to get a testcase for this, if you till have it.