服务器控件在render时,怎么样将子节点的内容以类似xml格式直接取出
自己编写服务器控件,需要在中间写一些自定义的XML格式的子节点例如: <asp:userControl>
<a>
<b attr1="attr1" attr2="attr2">
<c attr1="attr1" attr2="attr2">ccccc</c>
</b>
</a>
</asp:userControl>
其中子节点的层数和内容可以任意,希望在render的时候,可以将中间的<a>......</a>取出来。 --------------------编程问答-------------------- protected override void Render(HtmlTextWriter writer)
{
//base.Render(writer);
//
System.IO.StringWriter sw = new System.IO.StringWriter();
HtmlTextWriter htmlWriter = new HtmlTextWriter(sw);
base.Render(htmlWriter);
string html = sw.ToString(); // HERE !!!
// Response.Write(html); // 测试输出
} --------------------编程问答-------------------- 参考一下这段代码:
Imports Microsoft.VisualBasic
Imports System.Web.UI.WebControls
Namespace MyControls
<ParseChildren(False)> _
Public Class MyControl2
Inherits WebControl
Protected Overrides Sub AddParsedSubObject(ByVal obj As Object)
Dim litChild As LiteralControl = CType(obj, LiteralControl)
litChild.Text = HttpContext.Current.Server.HtmlEncode(litChild.Text)
MyBase.AddParsedSubObject(litChild)
End Sub
End Class
End Namespace --------------------编程问答-------------------- PersistenceMode(PersistenceMode.InnerProperty),DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
参考
http://www.aspxboy.com/code/default.aspx/S7s2zPJbeI9PJA/OKHpAVwVaUEhf02EgEOgeB3Yd5Z7fLL3ZNgdv7XIqertUOYm9swwXqZ4525aiPgV7zXEob8bofuU3o3aaupA3VCA9GE3c6fW3I5gsbG4Lk3V4bYgBrzsbLvmavWKRR2Zb2QhJIA==.Aspx
补充:.NET技术 , ASP.NET