ChtmlTextWriter.WriteBreak 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
br cHTML 출력 스트림에 요소를 씁니다.
public:
override void WriteBreak();
public override void WriteBreak();
override this.WriteBreak : unit -> unit
Public Overrides Sub WriteBreak ()
예제
이 섹션에는 두 가지 코드 예제가 포함되어 있습니다. 첫 번째 코드 예제에서는 cHTML 클래스 및 사용자 지정 속성을 만드는 방법을 보여 줍니다. 두 번째 코드 예제에서는 웹 페이지에서 사용자 지정 클래스를 사용하는 방법을 보여 줍니다.
사용자 지정 ChtmlSimplelabelAdapter 어댑터를 사용하려면 .NET Framework 구성 디렉터리의 브라우저에 대한 하위 디렉터리의 적절한 컴퓨터 전체 파일 또는 웹 애플리케이션 루트 아래의 App_Browsers 디렉터리에 있는 사용자 지정 브라우저 파일에 다음 코드를 추가합니다.
<controlAdapters>
<adapter controlType="AspNet.Samples.SimpleLabel"
adapterType="AspNet.Samples.ChtmlSimpleLabelAdapter" />
</controlAdapters>
다음 코드 예제에서는 명명 SimpleLabel된 클래스에 대 한 명명 ChtmlSimpleLabelAdapter 된 cHTML 어댑터 클래스를 만드는 방법을 보여 줍니다. 클래스가 클래스의 멤버에 ChtmlSimpleLabelAdapter 액세스할 수 있도록 하는 사용자 지정 Control 속성을 만든 다음 메서드를 Render 재정의 SimpleLabel 합니다. 재정의에서 다음과 같은 상황이 발생합니다.
메서드의 매개 변수로 전달되는 개체에서 HtmlTextWriter 파생되는 개체
w에 대한 참조 ChtmlTextWriter 를writerRender 만듭니다.문자열을 만들고 값과 동일하게
SimpleLabel.Text설정합니다.메서드를 EnterStyle 호출하여 레이블의 속성에 정의된 ControlStyle 스타일을 cHTML 출력 스트림에 적용합니다.
속성 값을 스트림에
Text쓰고 메서드를 호출 ExitStyle 하여 스타일 블록을 닫습니다.텍스트 및 스타일이 렌더링된
br후 출력 스트림에 요소를 렌더링하는 메서드를 호출 WriteBreak 합니다.
// Create a custom CHTML Adapter for a
// SimpleLabel class.
public class ChtmlSimpleLabelAdapter : WebControlAdapter
{
// Create the Control property to access
// the properties and methods of the
// SimpleLabel class.
protected SimpleLabel Control
{
get
{
return (SimpleLabel)base.Control;
}
}
// Override the Render method to render text
// in CHTML with the style defined by the control
// and a <br> element after the text and styles
// have been written to the output stream.
protected override void Render(HtmlTextWriter writer)
{
ChtmlTextWriter w = new ChtmlTextWriter(writer);
string value = Control.Text;
// Render the text of the control using
// the control's style settings.
w.EnterStyle(Control.ControlStyle);
w.Write(value);
w.ExitStyle(Control.ControlStyle);
w.WriteBreak();
}
}
' Create a custom CHTML Adapter for a
' class, named SimpleLabel.
Public Class ChtmlSimpleLabelAdapter
Inherits WebControlAdapter
' Create the Control property to access
' the properties and methods of the
' SimpleLabel class.
Protected Shadows ReadOnly Property Control() As SimpleLabel
Get
Return CType(MyBase.Control, SimpleLabel)
End Get
End Property
' Override the Render method to render text
' in CHTML with the style defined by the control
' and a <br> element after the text and styles
' have been written to the output stream.
Protected Overrides Sub Render(ByVal writer As HtmlTextWriter)
Dim w As ChtmlTextWriter = New ChtmlTextWriter(writer)
Dim value As String = Control.Text
' Render the text of the control using
' the control's style settings.
w.EnterStyle(Control.ControlStyle)
w.Write(value)
w.ExitStyle(Control.ControlStyle)
w.WriteBreak()
End Sub
End Class
다음 예제에서는 웹 페이지에서 클래스를 SimpleLabel 사용 하는 방법을 보여 줍니다.
<%@ Page Language="C#" %>
<%@ Import Namespace="AspNet.Samples" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
SimpleLabel sl = new SimpleLabel();
sl.ID = "SimpleLabel1";
sl.Text = "SimpleLabel Text";
PlaceHolder1.Controls.Add(sl);
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>CHtmlTextWriter Example</title>
</head>
<body>
<form id="form1" runat="server" >
<div>
<asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>
</div>
</form>
</body>
</html>
<%@ Page Language="VB" %>
<%@ Import Namespace="AspNet.Samples" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Dim sl As SimpleLabel = New SimpleLabel()
sl.ID = "SimpleLabel1"
sl.Text = "SimpleLabel Text"
PlaceHolder1.Controls.Add(sl)
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>CHtmlTextWriter Example</title>
</head>
<body>
<form id="form1" runat="server" >
<div>
<asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>
</div>
</form>
</body>
</html>
설명
cHTML WriteBreak 스트림에 줄 바꿈을 삽입하려면 이 메서드를 사용합니다.