IWebPart.Title 속성

정의

WebPart 컨트롤의 제목을 가져오거나 설정합니다.

public:
 property System::String ^ Title { System::String ^ get(); void set(System::String ^ value); };
public string Title { get; set; }
member this.Title : string with get, set
Public Property Title As String

속성 값

String

컨트롤의 제목이 들어 있는 문자열입니다. 기본값은 빈 문자열("")입니다.

예제

다음 코드 예제에서는 속성의 선언적 및 프로그래밍 방식으로 사용 하는 방법을 Title 보여 줍니다. 예제의 전체 소스 코드는 클래스 개요의 예제 섹션에 있습니다 IWebPart .

코드 예제의 첫 번째 부분에서는 사용자 컨트롤이 속성을 구현하는 방법을 보여 줍니다 Title .

public string Title
{
  get
  {
    object objTitle = ViewState["Title"];
    if (objTitle == null)
      return String.Empty;

    return (string)objTitle;
  }
  set
  {
    ViewState["Title"] = value;
  }
}
Public Property Title() As String _
  Implements IWebPart.Title
  Get
    Dim objTitle As Object = ViewState("Title")
    If objTitle Is Nothing Then
      Return String.Empty
    End If
    Return CStr(objTitle)
  End Get
  Set(ByVal value As String)
    ViewState("Title") = value
  End Set
End Property

코드 예제의 두 번째 부분에서는 사용자가 페이지의 라디오 단추에서 적절한 속성 이름을 선택하고 텍스트 상자에 새 값을 Title 설정한 다음 업데이트 단추를 클릭할 때 속성 값을 프로그래밍 방식으로 설정하는 사용자 컨트롤의 메서드를 보여 줍니다.

중요

이 예제에는 사용자 입력을 허용하는 텍스트 상자가 있으므로 보안상 위험할 수 있습니다. 기본적으로 ASP.NET 웹 페이지는 사용자 입력 내용에 스크립트 또는 HTML 요소가 포함되어 있지 않은지 확인합니다. 자세한 내용은 Script Exploits Overview를 참조하세요.

// Update the selected IWebPart property value.
void Button1_Click(object sender, EventArgs e)
{
  String propertyValue = Server.HtmlEncode(TextBox3.Text);
  TextBox3.Text = String.Empty;

  switch (RadioButtonList1.SelectedValue)
  {
    case "title":
      this.Title = propertyValue;
      break;
    case "description":
      this.Description = propertyValue;
      break;
    case "catalogiconimageurl":
      this.CatalogIconImageUrl = propertyValue;
      break;
    case "titleiconimageurl":
      this.TitleIconImageUrl = propertyValue;
      break;
    case "titleurl":
      this.TitleUrl = propertyValue;
      break;
    default:
      break;
  }
}
' Update the selected IWebPart property value.
Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)
  Dim propertyValue As String = Server.HtmlEncode(TextBox3.Text)
  TextBox3.Text = String.Empty
    
  Select Case RadioButtonList1.SelectedValue
    Case "title"
      Me.Title = propertyValue
    Case "description"
      Me.Description = propertyValue
    Case "catalogiconimageurl"
      Me.CatalogIconImageUrl = propertyValue
    Case "titleiconimageurl"
      Me.TitleIconImageUrl = propertyValue
    Case "titleurl"
      Me.TitleUrl = propertyValue
    Case Else
  End Select

End Sub 'Button1_Click

코드 예제의 세 번째 부분은 인터페이스를 구현 IWebPart 하는 사용자 컨트롤이 컨트롤에서 참조되는 방법과 컨트롤에서 WebPartZone 속성이 선언적으로 설정되는 방법을 Title 보여 줍니다.

<%@ page language="c#" %>
<%@ register tagprefix="uc1" 
    tagname="AccountUserControlCS" 
    src="AccountUserControlcs.ascx"%>
<!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>
      Personalizable User Control with IWebPart Properties
    </title>
  </head>
  <body>
    <form id="form1" runat="server">
      <asp:webpartmanager id="WebPartManager1" runat="server" />
      <asp:webpartzone 
        id="zone1" 
        runat="server" 
        headertext="Main" 
        CloseVerb-Enabled="false">
        <zonetemplate>
          <uc1:AccountUserControlCS 
            runat="server" 
            id="accountwebpart" 
            title="Account Form"
            Description="Account Form with default values."
            CatalogIconImageUrl="MyCatalogIcon.gif"
            TitleIconImageUrl="MyTitleIcon.gif"
            TitleUrl="MyUrl.html"/>
        </zonetemplate>
      </asp:webpartzone>    
    </form>
  </body>
</html>
<%@ page language="VB" %>
<%@ register tagprefix="uc1" 
    tagname="AccountUserControlVB" 
    src="AccountUserControlvb.ascx"%>
<!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>
      Personalizable User Control with IWebPart Properties
    </title>
  </head>
  <body>
    <form id="form1" runat="server">
      <asp:webpartmanager id="WebPartManager1" runat="server" />
      <asp:webpartzone 
        id="zone1" 
        runat="server" 
        headertext="Main" 
        CloseVerb-Enabled="false">
        <zonetemplate>
          <uc1:AccountUserControlVB 
            runat="server" 
            id="accountwebpart" 
            title="Account Form"
            Description="Account Form with default values."
            CatalogIconImageUrl="MyCatalogIcon.gif"
            TitleIconImageUrl="MyTitleIcon.gif"
            TitleUrl="MyUrl.html"/>
        </zonetemplate>
      </asp:webpartzone>    
    </form>
  </body>
</html>

설명

컨트롤의 제목 표시줄에 표시되는 제목 텍스트는 속성에 Title 의해 설정됩니다.

컨트롤에 제목을 제공하지 않으면 웹 파트 컨트롤 집합은 타이틀로 사용할 기본 문자열을 자동으로 계산합니다. 자세한 내용은 DisplayTitle를 참조하세요. 또한 제목 문자열에 추가되는 기본 부제목을 제공할 수 있습니다. 자세한 내용은 Subtitle를 참조하십시오.

적용 대상

추가 정보