[英]How to display xml string in a Label?
我试图在下面获取我的HTML方法,以对字符串进行编码并将其显示在标签上,但是在客户端,我一直得到空白页。
我检查了viewsource,它也没有显示HTML输出。
public partial class About : Page
{
protected void Page_Load(object sender, EventArgs e, string data)
{
if (!IsPostBack)
{
string a = createXMLPub(data);
// Label1.Text = HttpUtility.HtmlEncode(a);
Label1.Text = Server.HtmlEncode(a);
}
}
public static string createXMLPub(string data )
{
XElement xeRoot = new XElement("pub");
XElement xeName = new XElement("name", "###");
xeRoot.Add(xeName);
XElement xeCategory = new XElement("category", "#####");
xeRoot.Add(xeCategory);
XDocument xDoc = new XDocument(xeRoot);
data = xDoc.ToString();
return data;
}
的HTML
<asp:Content runat="server" ID="BodyContent" ContentPlaceHolderID="MainContent">
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</asp:Content>
请提出建议,以防止我将此代码弄错了。 非常感谢
Page_Load
未触发-重新:额外的string data
参数与事件委托的签名不匹配 所以:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string a = createXMLPub();
Label1.Text = Server.HtmlEncode(a);
}
}
public static string createXMLPub()
{
XElement xeRoot = new XElement("pub");
XElement xeName = new XElement("name", "###");
xeRoot.Add(xeName);
XElement xeCategory = new XElement("category", "#####");
xeRoot.Add(xeCategory);
XDocument xDoc = new XDocument(xeRoot);
return xDoc.ToString();
}
嗯...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.