Yeah, sorry, it's on a computer at my other office, but I think I remember it pretty clearly as I burned out a Saturday on it (this past weekend).
What I was trying to do with the HtmlForm was something like was done in a blog posted
here, just with adding dropdown items from SharePoint list items instead of buttons from XML items, but the concept is the exact same, so it seemed there was a proof of concept out there, already:
- private void Page_Load(object sender, System.EventArgs e)
-
{
-
XPathDocument doc = new XPathDocument(Server.MapPath("xmlfile1.xml"));
-
XslTransform trans = new XslTransform();
-
trans.Load(Server.MapPath("xsltfile1.xslt"));
-
-
System.IO.StringWriter writer = new System.IO.StringWriter();
-
trans.Transform(doc,null,writer);
-
writer.Flush();
-
System.Text.StringBuilder sb = writer.GetStringBuilder();
-
-
System.Web.UI.Control parsedControl = Page.ParseControl(sb.ToString());
-
HtmlForm form = (HtmlForm)Page.FindControl("WebForm1");
-
for (int i=0;i< parsedControl.Controls.Count;i++)
-
{
-
HtmlInputButton button = parsedControl.Controls[i] as HtmlInputButton;
-
if(null != button)
-
{
-
button.ServerClick += new System.EventHandler(this.Button_Click);
-
form.Controls.Add(button);
-
}
-
}
-
}
So that didn't work for adding my dropdown. I tried putting it in Page_Init and adding it to a panel, just as you suggested, and while that worked later for what I did in the User Control, it didn't work here.
What I tried was doing something like this:
- protected void Page_Init(object sender, EventArgs e)
-
{
-
string[] myVals;
-
string[] myText;
-
-
// pretend there is code here to return my list items
-
// into the array objects above... too lengthy to type
-
// or read, but I did not have to modify it to get it
-
// working, so I know it wasn't the problem
-
-
DropDownList ddl = new DropDownList();
-
for (int i=0;myVals.length;i++)
-
{
-
ddl.Items.Add(new ListItem(myText[i],myVals[i]);
-
}
-
ddl.AutoPostBack = true;
-
myPagePanel.Controls.Add(ddl);
-
}
And doing this (or something pretty close - I don't have the exact code in front of me right now) would not render my control to "myPagePanel", the asp:Panel I created on my page (probably didn't have that ID, but you get the idea).
When I just moved that same exact code to my User Control, and added the User Control dynamically to the main page through it's Page_Init like you did, all was happy in the land of Nod. Not sure why.
-Tom