HttpResponse.Output 屬性

定義

允許文字輸出至傳出 HTTP 回應資料流。

C#
public System.IO.TextWriter Output { get; }
C#
public System.IO.TextWriter Output { get; set; }

屬性值

TextWriter

TextWriter 物件,允許自訂輸出至用戶端。

範例

下列範例是 ASP.NET 網頁,其中包含 TextBoxTextMode 屬性設定為 MultiLine 的控制項。 頁面的程式碼會採用使用者輸入的 TextMode 文字,使用 HtmlEncode 方法來將它編碼,而 Output 屬性則會將編碼字串顯示至頁面。

ASP.NET (C#)
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

    // When the page is posted back, the text box's 
    // Text property value is HTML encoded and sent
    // sent to the current Response.
    void btnSubmit_Click(object sender, EventArgs e) {

        if (IsPostBack)
        {
            Server.HtmlEncode(txtSubmitString.Text, Response.Output);
        }
    }

</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>ASP.NET Example</title>
</head>
<body>
    <form id="form1" runat="server">
        <p style="font-family:Tahoma; font-size:12">
            Enter your comments here:
        </p>
        <p>
            <asp:TextBox id="txtSubmitString" runat="server" Width="181px" TextMode="MultiLine"></asp:TextBox>
        </p>
        <p>
            <asp:Button id="btnSubmit" onclick="btnSubmit_Click" runat="server" Text="Submit"></asp:Button>
        </p>
        <p>
            <asp:Label id="lblEncodedString" runat="server"></asp:Label>
        </p>
    </form>
</body>
</html>

適用於

產品 版本
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8