LoadControl() and Constructor Parameters

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Sam Kuehn (samkuehn_at_hotmail.com)
Date: 02/10/05


Date: Thu, 10 Feb 2005 13:25:41 -0800

How do I accomplish the fallowing (is it even possible). Say I write a UserControl
"MyControl.ascx". Now I use LoadControl("MyControl.ascx"). But I really
want MyControl to require parameters in the constructor for example MyContorl
oMyControl = new MyContorl(employeeid). However I need to load the control
at runtime so the have to call it this way LoadControl("MyControl.ascx")
and I get an error that I have not supplied any parameter to the constructor.
 Is there anyway around this? I guess I could change the control so that
I can insatiate it without supplying parameters and assigning the properties
later; but that doesn't seem like a very clean solution. Thanks in advance.



Relevant Pages

  • Re: Windows.Forms.TabPage beerben
    ... Und wieso wird man bei der Erstellung eines neues UserControls nicht gefragt, ob man eine andere Basis haben möchte als UserControl? ... Erstelle dann eine neue Instanz davon und speichere sie als Referenz in deiner Form (das die TabPage enthält), damit du später darauf zugreifen kannst. ... Dann weise dein Control einfach ... {control = new MyControl; tabs.Controls.Add;} ...
    (microsoft.public.de.german.entwickler.dotnet.csharp)
  • Re: User Controls
    ... panels Maybe you can take some of this code and put it to use: ... Dim myControl as UserControl ... > the application that starts another control that opens in a panel. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: LoadControl() and Constructor Parameters
    ... Controls have to have a paramerter-less constructor. ... factory type pattern to keep a clean design. ... >want MyControl to require parameters in the constructor for example MyContorl ... However I need to load the control ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Get Parent Collection?
    ... If you have ArrayList before you call new MyControl() you can modify ... In the constructor just save passed reference for future use and ... ... Or you can add setter property in control, ...
    (microsoft.public.dotnet.framework.windowsforms)
  • Re: How cancel a Copy operation?
    ... hidden to the IDE Toolbox and finally with just an attached designer. ... Public Overloads Overrides Function CanParent(ByVal aControl As Control) As ... Your goal is to manage MyControl via code only, ...
    (microsoft.public.dotnet.framework.windowsforms.designtime)