简体   繁体   中英

Insert .NET server control to a DIV with Html Agility Pack

I selected a DIVlike this:

var divEl = doc.DocumentNode.SelectSingleNode("//div[@id='" + field.Id + "']");

This DIV is empty. Now I need to add a .NET TextBox server control to this DIV and then send the DIV back to the client. How?

First you need to create an element representing the textbox, add the textbox as a child to the div and save the document to whatever stream you have open to the client.

var xpath = String.Format("//div[@id='{0}']", field.Id);
var div = doc.DocumentNode.SelectSingleNode(xpath);
if (div != null)
{
    var textBox = HtmlNode.CreateNode("<asp:TextBox runat='server' />");
    div.AppendChild(textBox);
}

doc.Save(stream);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM