打印 html 的最佳方式是什么?
我能做到:
container.InnerHtml = "<input type=\"text\" ...runat=..>";
哪里container
是对 <div>
的引用HTML
但我觉得这不是正确的模式。 有人可以指出我正确的方向吗?
提前致谢。
最佳答案
正如 Paolo 所提到的,使用 <asp:PlaceHolder>
是在运行时注入(inject) HTML 的好方法。它不仅允许您输出纯 html <div><p>Hello World!</p></div>
但它也允许您动态添加其他 asp.net 控件。
对于上面的示例,您可以这样做
.aspx
<asp:PlaceHolder id="PlaceHolder1" runat="server" />
c#
TextBox textBox1 = new TextBox();
textBox1.Id = "textBox1";
textBox1.TextMode = TextBoxMode.SingleLine;
PlaceHolder1.Controls.Add(textBox1);
这允许您动态访问您输入到 textBox1 中的值。
关于c# - 在 asp.net 中打印 html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7243952/