Setting UserControls properties at Runtime

  • Thread starter Thread starter SamIAm
  • Start date Start date
S

SamIAm

I have a UserControl called "MyControl" The content it delivers is varied my
a parameter: "LanguageID"

<uc1:MyControl id="MainNavigationControl" runat="server" LanguageID="<% What
do I do here%>"></uc1:MyControl >

How do I set the property at run time. I have tried loading the control
using the LoadControl function but get errors when I do a cast to set the
LanguageID property i.e.
Control nav = LoadControl("MyControl.ascx");
((MyControl)nav).LanguageID = "en-US";
somePlaceHolder.Controls.Add(nav);

Any ideas or pointer to resources?

S
 
Do'nt bind the user control at designtime like you dit in HTML, but do it
all at runtime is problably the most simple solution.
 
I have tried binding at runtime but cannot set any properties as I get cast
exceptions (see code below)??
 
Back
Top