User Control constructor has parameters
-
I build a user control and added a constructor to it. The constructor takes a parameter. Now when I put the user control in a web form (drag and drop) I don't know where to set the parameter. What happens is that I get this error: Compiler Error Message: CS1501: No overload for method 'ItemFields' takes '0' arguments Source Error: Line 31: private static bool __initialized = false; Line 32: Line 33: public ItemFields_ascx() { Line 34: if ((ASP.ItemFields_ascx.__initialized == false)) { Line 35: ASP.ItemFields_ascx.__initialized = true; Source File: c:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\Temporary ASP.NET Files\AspProjectOne\2eab3c48\dc018b2c\onc_fead.0.cs Line: 33 Thing is I don't know WHERE to initialize the control with the parameter for the constructor. I was wondering if in the ASPX page is the right place: orHere??? Edd
-
I build a user control and added a constructor to it. The constructor takes a parameter. Now when I put the user control in a web form (drag and drop) I don't know where to set the parameter. What happens is that I get this error: Compiler Error Message: CS1501: No overload for method 'ItemFields' takes '0' arguments Source Error: Line 31: private static bool __initialized = false; Line 32: Line 33: public ItemFields_ascx() { Line 34: if ((ASP.ItemFields_ascx.__initialized == false)) { Line 35: ASP.ItemFields_ascx.__initialized = true; Source File: c:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\Temporary ASP.NET Files\AspProjectOne\2eab3c48\dc018b2c\onc_fead.0.cs Line: 33 Thing is I don't know WHERE to initialize the control with the parameter for the constructor. I was wondering if in the ASPX page is the right place: orHere??? Edd
Look at the code behind. You should see it being instantiated using the default constructor.
-
Look at the code behind. You should see it being instantiated using the default constructor.
I found out on MSDN that when drag dropping a control Visual Studio doesn't automatically create the declaration in the Code behind file. In fact if our control is called UserControl1 and is has a public property called StringProperty we cannot access it by default by calling UserControl1.StringProperty = "hello"; On MSDN they say to add protected UserControl UserControl1; Done this and accessing the control works. Anyway I still haven initialized my constructor. If I modify my declaration to protected UserControl UserControl1 = new UserControl(ab1, ab2, ab3....) I still receive the error no overloaded method for UserControl takes 0 parameters. I used a workaround of declaring a property and assigning it to the value I want on the Page_Load in my case works but there must be a proper way to do this. Edd