HtmlDesignerAttribute 类

定义用于 Web 部件自定义属性的HtmlDesigner属性。指定如果自定义属性使用自定义生成器和的生成器,URL 或自定义属性不使用任何生成器,包括任何默认生成器。

继承层次结构

System.Object
  System.Attribute
    Microsoft.SharePoint.WebPartPages.HtmlDesignerAttribute

命名空间:  Microsoft.SharePoint.WebPartPages
程序集:  Microsoft.SharePoint(位于 Microsoft.SharePoint.dll 中)

语法

声明
<AttributeUsageAttribute(AttributeTargets.Property)> _
<AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
Public NotInheritable Class HtmlDesignerAttribute _
    Inherits Attribute
用法
Dim instance As HtmlDesignerAttribute
[AttributeUsageAttribute(AttributeTargets.Property)]
[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public sealed class HtmlDesignerAttribute : Attribute

备注

当在 Microsoft Visual Studio 2005 中打开 Web 部件时,则将忽略HtmlDesignerAttribute类。将使用默认的 Visual Studio 2005 生成器。

示例

下面的代码示例显示具有使用HtmlDesignerAttribute定义静态的自定义生成器的自定义属性的 Web 部件。

using System;
using System.ComponentModel;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml.Serialization;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Utilities;
using Microsoft.SharePoint.WebPartPages;
using System.Xml;

namespace WebPartLibrary2
{
    
    [XmlRootAttribute(Namespace="WebPartLibrary2")]

    
    public class HtmlDesignerAttributeTestPart: WebPart
    {
        ///    Member variable for a property with 
        ///    HtmlDesignerAttribute defined for a custom builder
        private string customPropertyValue = "This Web Part has a custom property";
        
        /// <summary>
        ///        Use HtmlDesignerAttribute to define a static custom 
        ///        builder builder.aspx for the custom property.
        /// </summary>
        [WebPartStorage(Storage = Storage.Personal), 
        DefaultValue(""), 
        HtmlDesignerAttribute("http://myserver/builder.aspx")]
        public string CustomProperty
        {
            get
            {
                return customPropertyValue;
            }
            set
            {    
                customPropertyValue = value;
            }
        }
        
        /// <summary>
        ///        Renders the content of the HtmlDesignerAttributeTestPart.
        /// </summary>
        protected override void RenderWebPart (HtmlTextWriter output)
        {
            output.Write(SPEncode.HtmlEncode(CustomProperty));
        }
    }

}
Imports System
Imports System.ComponentModel
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Xml.Serialization
Imports Microsoft.SharePoint
Imports Microsoft.SharePoint.Utilities
Imports Microsoft.SharePoint.WebPartPages
Imports System.Xml

Namespace WebPartLibrary2

    <XmlRootAttribute(Namespace:="WebPartLibrary2")> _
    Public Class HtmlDesignerAttributeTestPart
        Inherits WebPart
        '''    Member variable for a property with 
        '''    HtmlDesignerAttribute defined for a custom builder
        Private customPropertyValue As String = "This Web Part has a custom property"

        ''' <summary>
        '''        Use HtmlDesignerAttribute to define a static custom 
        '''        builder builder.aspx for the custom property.
        ''' </summary>
        <WebPartStorage(Storage := Storage.Personal), DefaultValue(""), HtmlDesignerAttribute("http://myserver/builder.aspx")> _
        Public Property CustomProperty() As String
            Get
                Return customPropertyValue
            End Get
            Set(ByVal value As String)
                customPropertyValue = value
            End Set
        End Property

        ''' <summary>
        '''        Renders the content of the HtmlDesignerAttributeTestPart.
        ''' </summary>
        Protected Overrides Sub RenderWebPart(ByVal output As HtmlTextWriter)
            output.Write(SPEncode.HtmlEncode(CustomProperty))
        End Sub
    End Class

End Namespace

线程安全性

该类型的任何公共 静态 (已共享 在 Visual Basic 中) 成员都是线程安全的。不保证任何实例成员都是线程安全的。

另请参阅

引用

HtmlDesignerAttribute 成员

Microsoft.SharePoint.WebPartPages 命名空间