I have a web User Control (.ascx file) and I would like to initialize some private members. But if I try to create a parameterless constructor like this:
<%@ Control Language="C#" ClassName="MyControl" %>
public MyControl() { }
I get the error:
Type ‘ASP.MyControl’ already defines a member called ‘MyControl’
with the same parameter types
with a source file that’s under C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\...
I just had the same problem. How I solved it was to create a base class with a method that I will use in the user control to do whatever it is that needs doing.
(Edit: I forgot to mention that my base class is also marked abstract)
In the base class define:
The base class calls this in it’s own constructor:
Then in the usercontrol I inherit the base class in the page directives:
The final step is to actually implement the new method in the usercontrol:
That was my solution.