1

C# で asp.net を使用して作成された MasterPage があります。これには、私のメニューなどが含まれます。XDocument を動的に作成します。それから私は使用します:

Response.Write(outputDoc);

to display my XDocument as a webpage. It displays as expected, but it overwrites my MasterPage. I really want to put outputDoc in a container on my MasterPage but I can't find a way to do it.

I am completely lost on this. I must be using the wrong terminology, or trying to do this the completely wrong way because I can't find anything remotely relevant using Google.

Thanks for any assistance.

4

1 に答える 1

2

おそらく、 Literalコントロールを使用して、そのコンテンツをoutputDoc XDocumentのコンテンツに設定できます。

.aspx ページのコード

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Literal ID="Literal1" runat="server" />
        <asp:Literal ID="Literal2" runat="server" />
        <asp:Literal ID="Literal3" runat="server" />
    </div>
    </form>
</body>
</html>

.aspx.cs ページのコード

using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Literal1.Mode = LiteralMode.Encode;
        Literal2.Mode = LiteralMode.PassThrough;
        Literal3.Mode = LiteralMode.Transform;

        Literal1.Text = @"<font size=4 color=red>Literal1 with Encode property example</font><script>alert(""Literal1 with the Encode property"");</script></br></br>";

        Literal2.Text = @"<font size=4 color=green>Literal2 with PassThrough property example</font><script>alert(""Literal2 with the PassThrough property"");</script></br></br>";

        Literal3.Text = @"<font size=4 color=blue>Literal3 with Encode Transform example</font><script>alert(""Literal3 with the Transform property"");</script></br></br>";
    }
}

例と詳細については、 http://www.c-sharpcorner.com/uploadfile/puranindia/literal-control-in-Asp-Net/をご覧ください。

于 2013-09-02T19:25:45.457 に答える