Is there a way to pass the parameters to the LoadControl function when loading the user control dynamically?
+1
A:
All you need to do is create a descendant of the UserControl class, add a default constructor and another constructor that takes your parameters. The parameterless constructor is necessary for designer support.
public class MyControl : UserControl
{
public MyControl() : base()
{
// do initialization stuff...
}
public MyControl(int parameter) : this()
{
// do additional stuff with parameter
}
}
Thorsten Dittmar
2009-06-05 06:49:21
Thanks, yes, I know how to write a constructor:) I was more referring to the dynamic User Control creation with LoadControl function. How do I pass a parameter to the constructor to this function. Sorry, if I weren't clear.
gnomixa
2009-06-05 17:05:13
I thought the problem was with the Visual Studio designer not displaying the user control (which may be the case when you do not provide a parameterless constructor)...
Thorsten Dittmar
2009-06-08 14:41:48