Well, I had to do this to get it to work...
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Control myControl = LoadControl("~/Home/Controls/TestControl.ascx");
myControl.ID = "lblMyLabel";
GenericWebPart webPart = myWebPartManager.CreateWebPart(myControl);
webPart.Title = "This is the test title";
myWebPartManager.AddWebPart(webPart, WebPartZone2, 0);
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:WebPartManager ID="myWebPartManager" runat="server" />
<asp:WebPartZone ID="WebPartZone2" runat="server" PartStyle-Width="100%" Width="250" />
</div>
</form>
</body>
</html>
However, I'm still unable to dynamically create a WebPart using all
C# code like I tried to do in my original post though. ANy help with that would be appreciated.
Thanks,
Rich
Rich
http://www.DevAndDesign.com/