简体   繁体   English

将.NET服务器控件插入到具有HTML Agility Pack的DIV中

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

I selected a DIVlike this: 我选择了这样的DIV:

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

This DIV is empty. 该DIV为空。 Now I need to add a .NET TextBox server control to this DIV and then send the DIV back to the client. 现在,我需要向此DIV添加.NET TextBox服务器控件,然后将DIV发送回客户端。 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. 首先,您需要创建一个表示文本框的元素,将该文本框作为子元素添加到div,然后将文档保存到向客户端打开的任何流中。

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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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