WebControls

  • Thread starter Thread starter Ian Frawley
  • Start date Start date
I

Ian Frawley

Hi all,

I am trying to create a number of System.Web.UI.WebControls on the fly
depending on config info so I did this
Type type = Type.GetType("System.Web.UI.WebControls." + row.ObjectType);

System.Web.UI.Control temp =
(System.Web.UI.Control)Activator.CreateInstance(type);

But unfortunatley type is always null. I have started looking into
reflection and got a bit lost has anyone done this sort of thing before?

Cheers
 
Sorted I figured it out myself-ish
You have to pass in ", System.Web,Version=1.0.3300.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a" as part of the GetType String.

Woohoo its works bloody marvelously and no hardcoding whatso ever.
 
can you post this code, it's got my attention.

--
Regards,
Alvin Bruney [ASP.NET MVP]
Got tidbits? Get it here...
http://tinyurl.com/3he3b
Ian Frawley said:
Sorted I figured it out myself-ish
You have to pass in ", System.Web,Version=1.0.3300.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a" as part of the GetType String.

Woohoo its works bloody marvelously and no hardcoding whatso ever.
 
Here you go, works a right treat.

public void GenerateFields(string ID, string Metric)
{
ActionID = Convert.ToInt32(ID);
MetricName = Metric;
lblActionID.Text = Metric;

ActionsWebService.Actions actionsweb = new ActionsWebService.Actions();
// MY WEB SERVICE
ActionsWebService.ActionObjects objects =
actionsweb.GetActionObjects(ActionID); // A STRONGLY TYPED DATASET

foreach(ActionsWebService.ActionObjects.ObjectsRow row in
objects.Objects)
{

Type type = Type.GetType("System.Web.UI.WebControls." +
row.ObjectType + ", System.Web,Version=1.0.3300.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a");
System.Web.UI.Control temp =
(System.Web.UI.Control)Activator.CreateInstance(type);

TableRow tr = new TableRow();
TableCell tcObject = new TableCell();
tcObject.Controls.Add(temp);
TableCell tcObjectDescription = new TableCell();
tcObjectDescription.Text = row.FriendlyName.ToString();
tr.Cells.Add(tcObject);
tr.Cells.Add(tcObjectDescription);
controlsTable.Rows.Add(tr);
}
}
 
Back
Top