|Problem with -> ASP.NET using C#
I am creating a custom user control that reads an xml file and dynamically places labels on the control. This user control will then be placed inside a webform
I am suddenly stuck because I know if I wanted to add dynamically generated controls without a custom user control, which I probably may end up doing if this does not work, I could easily just add this under OnInit function (which is generated by the forms designer.
override protected void OnInit(EventArgs e)
// Create dynamic controls here.
// Use "using System.Web.UI.WebControls;"
TextBox1 = new TextBox();
TextBox1.ID = "TextBox1";
TextBox1.Style["Position"] = "Absolute";
TextBox1.Style["Top"] = "25px";
TextBox1.Style["Left"] = "100px";
yeah thats from this Q Article.
Thats all fine and good, but you see this line:
What would be the equivalent in a custom User control.
Say my Control is called MyControl.ascx
in my function that reads the xml file and attempts to programatically create a label, every thing is just peachy..but how do I place the label inside my custom control?
I cannot do this:
MyControl somecontrol = new MyControl();
and then in the function do
Cannot create instance of Abstract class or interface? Bah!
I guess I will do it directly from the WebForm, but I just thought there was tremendous coolness value to get it working through a custom control that I could add to a webform without cluttering the webform with all this.
Oh well...if anyone has comments about creating an instance of an abstract class please post!