T
Tim
I am trying to load both server and user controls into placeholder
controls on a aspx template page at runtime. These values would be
strings that are returned from a database query. I know I can do this
for user controls easily using:
oContent = (ControlBase) Page.LoadControl(Session["Page"] + ".ascx");
this.plcContent.Controls.Add(oContent);
but can not figure out how to do it for server controls. since I do
not know what the control will be that will be on the page at design
time I do not just want to create a bunch of controls then loop
through them to return that type.
the closest I have found on the web was where someone else was trying
to do the same thing. How ever his example did not work.
Assembly ass = Assembly.LoadFrom("c:\\windows\\microsoft.net\\framework\\v1.1.4322\\System.Web.dll");
Type typ = ass.GetType("System.Web.UI.WebControls.TextBox", true,
false);
ConstructorInfo ci = typ.GetConstructor (System.Type.EmptyTypes);
WebControl ctrl = (WebControl)ci.Invoke(null);
this.plcContent.Controls.Add(ctrl);
this code blows during the invoke method.
Can someone help me here and also tell me if this is a bad idea to be
loading the controls based on a result set from the database.
controls on a aspx template page at runtime. These values would be
strings that are returned from a database query. I know I can do this
for user controls easily using:
oContent = (ControlBase) Page.LoadControl(Session["Page"] + ".ascx");
this.plcContent.Controls.Add(oContent);
but can not figure out how to do it for server controls. since I do
not know what the control will be that will be on the page at design
time I do not just want to create a bunch of controls then loop
through them to return that type.
the closest I have found on the web was where someone else was trying
to do the same thing. How ever his example did not work.
Assembly ass = Assembly.LoadFrom("c:\\windows\\microsoft.net\\framework\\v1.1.4322\\System.Web.dll");
Type typ = ass.GetType("System.Web.UI.WebControls.TextBox", true,
false);
ConstructorInfo ci = typ.GetConstructor (System.Type.EmptyTypes);
WebControl ctrl = (WebControl)ci.Invoke(null);
this.plcContent.Controls.Add(ctrl);
this code blows during the invoke method.
Can someone help me here and also tell me if this is a bad idea to be
loading the controls based on a result set from the database.