WebPartZoneBase.OnCreateVerbs(WebPartVerbsEventArgs) 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
CreateVerbs 이벤트를 발생시킵니다.
protected:
virtual void OnCreateVerbs(System::Web::UI::WebControls::WebParts::WebPartVerbsEventArgs ^ e);
protected virtual void OnCreateVerbs (System.Web.UI.WebControls.WebParts.WebPartVerbsEventArgs e);
abstract member OnCreateVerbs : System.Web.UI.WebControls.WebParts.WebPartVerbsEventArgs -> unit
override this.OnCreateVerbs : System.Web.UI.WebControls.WebParts.WebPartVerbsEventArgs -> unit
Protected Overridable Sub OnCreateVerbs (e As WebPartVerbsEventArgs)
매개 변수
이벤트 데이터가 포함된 EventArgs입니다.
예제
다음 코드 예제에서는 파생 WebPartZoneBase 영역에 사용자 지정 동사를 추가 하는 메서드를 재정의 OnCreateVerbs 하여 이벤트에 대 CreateVerbs 한 처리기를 만드는 방법을 보여 줍니다.
코드 예제에는 두 개의 소스 파일이 포함되어 있습니다. 코드 예제를 실행하려면 이 소스 코드를 컴파일해야 합니다. 명시적으로 컴파일하고 결과 어셈블리를 웹 사이트의 Bin 폴더 또는 전역 어셈블리 캐시에 넣을 수 있습니다. 또는 소스 코드를 사이트의 App_Code 폴더에 배치하여 런타임에 동적으로 컴파일할 수 있습니다. 이 코드 예제에서는 동적 컴파일을 사용합니다. 컴파일 방법을 보여 주는 연습은 연습: 사용자 지정 웹 서버 컨트롤 개발 및 사용을 참조하세요.
코드 예제의 첫 번째 부분은 클래스에서 파생된 간단한 컨트롤에 대한 소스 코드입니다 WebPart .
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Security.Permissions;
using System.Collections.Generic;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
namespace Samples.AspNet.CS.Controls
{
// This code snippet creates a simple Web Part control.
[AspNetHostingPermission(SecurityAction.Demand,
Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermission(SecurityAction.InheritanceDemand,
Level = AspNetHostingPermissionLevel.Minimal)]
public class SimpleControl : WebPart
{
private String _text = "Simple control text";
public string Text
{
get
{
if (_text != null)
return _text;
else
return string.Empty;
}
set { _text = value; }
}
protected override void Render(System.Web.UI.HtmlTextWriter
writer)
{
writer.Write(this.Text);
}
}
}
Imports System.Data
Imports System.Configuration
Imports System.Web
Imports System.Web.Security
Imports System.Collections.Generic
Imports System.Security.Permissions
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls
' This code snippet creates a simple Web Part control.
Namespace Samples.AspNet.VB.Controls
<AspNetHostingPermission(SecurityAction.Demand, _
Level:=AspNetHostingPermissionLevel.Minimal)> _
<AspNetHostingPermission(SecurityAction.InheritanceDemand, _
Level:=AspNetHostingPermissionLevel.Minimal)> _
Public Class SimpleControl
Inherits System.Web.UI.WebControls.WebParts.WebPart
Private _text As String = "Simple control text"
Public Property [Text]() As String
Get
If Not (_text Is Nothing) Then
Return _text
Else
Return String.Empty
End If
End Get
Set(ByVal value As String)
_text = value
End Set
End Property
Protected Overrides Sub Render(ByVal writer _
As System.Web.UI.HtmlTextWriter)
writer.Write(Me.Text)
End Sub
End Class
End Namespace
코드 예제의 두 번째 부분은 메서드를 재정 OnCreateVerbs 의하여 영역에 사용자 지정 동사를 추가하는 파생 WebPartZoneBase 영역에 대한 소스 코드입니다. 또한 이 코드는 영역에 포함된 컨트롤의 WebPart 동사 메뉴에 표시되는 사용자 지정 동사를 만들고 동사는 현재 WebPart 컨트롤의 또 다른 복사본을 만듭니다.
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Security.Permissions;
using System.Collections.Generic;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
namespace Samples.AspNet.CS.Controls
{
/*
This code sample creates a Web Part zone and adds the
"Copy Web Part" verb to any control in the zone.
*/
[AspNetHostingPermission(SecurityAction.Demand,
Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermission(SecurityAction.InheritanceDemand,
Level = AspNetHostingPermissionLevel.Minimal)]
public class ZoneWithAddedVerb : WebPartZone
{
protected override void OnCreateVerbs(WebPartVerbsEventArgs e)
{
List<WebPartVerb> newVerbs = new List<WebPartVerb>();
newVerbs.Add(new CopyWebPartVerb(CopyWebPartToNewOne));
e.Verbs = new WebPartVerbCollection(e.Verbs,newVerbs);
base.OnCreateVerbs(e);
}
void CopyWebPartToNewOne(object sender, WebPartEventArgs e)
{
WebPartManager wpmgr =
WebPartManager.GetCurrentWebPartManager(Page);
System.Web.UI.WebControls.WebParts.WebPart wp;
Type tp = e.WebPart.GetType();
wp = (System.Web.UI.WebControls.WebParts.WebPart)Activator.CreateInstance(tp);
wpmgr.AddWebPart(wp, e.WebPart.Zone, e.WebPart.ZoneIndex + 1);
}
}
[AspNetHostingPermission(SecurityAction.Demand,
Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermission(SecurityAction.InheritanceDemand,
Level = AspNetHostingPermissionLevel.Minimal)]
internal class CopyWebPartVerb : WebPartVerb
{
private const String _copyWebPartImageUrl = "~/CopyVerb.ico";
internal CopyWebPartVerb(WebPartEventHandler serverClickHandler) :
base("MyVerb", serverClickHandler)
{ }
public override string Text
{
get { return "Copy Web Part"; }
set { ;}
}
public override string Description
{
get { return "This verb will copy this web part control " +
"to a new one below"; }
set { ; }
}
public override bool Enabled
{
get { return base.Enabled; }
set { base.Enabled = value; }
}
public override string ImageUrl
{
get { return _copyWebPartImageUrl; }
set { ; }
}
}
}
Imports System.Data
Imports System.Configuration
Imports System.Web
Imports System.Web.Security
Imports System.Security.Permissions
Imports System.Collections.Generic
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls
' This code sample creates a Web Part zone and adds the
' "Copy Web Part" verb to any control in the zone.
Namespace Samples.AspNet.VB.Controls
<AspNetHostingPermission(SecurityAction.Demand, _
Level:=AspNetHostingPermissionLevel.Minimal)> _
<AspNetHostingPermission(SecurityAction.InheritanceDemand, _
Level:=AspNetHostingPermissionLevel.Minimal)> _
Public Class ZoneWithAddedVerb
Inherits WebPartZone
'public class ExtendedWebPartZoneBase
Protected Overrides Sub OnCreateVerbs(ByVal e _
As WebPartVerbsEventArgs)
Dim newVerbs As List(Of WebPartVerb) = _
New List(Of WebPartVerb)
newVerbs.Add(New CopyWebPartVerb(AddressOf CopyWebPartToNewOne))
e.Verbs = New WebPartVerbCollection(e.Verbs, newVerbs)
MyBase.OnCreateVerbs(e)
End Sub
Sub CopyWebPartToNewOne(ByVal sender As Object, _
ByVal e As WebPartEventArgs)
Dim wpmgr As WebPartManager = _
WebPartManager.GetCurrentWebPartManager(Page)
Dim wp As System.Web.UI.WebControls.WebParts.WebPart
Dim tp As Type = e.WebPart.GetType()
wp = CType(Activator.CreateInstance(tp), _
System.Web.UI.WebControls.WebParts.WebPart)
wpmgr.AddWebPart(wp, e.WebPart.Zone, e.WebPart.ZoneIndex + 1)
End Sub
End Class
<AspNetHostingPermission(SecurityAction.Demand, _
Level:=AspNetHostingPermissionLevel.Minimal)> _
<AspNetHostingPermission(SecurityAction.InheritanceDemand, _
Level:=AspNetHostingPermissionLevel.Minimal)> _
Friend Class CopyWebPartVerb
Inherits WebPartVerb
Private Const _copyWebPartImageUrl As String = "~/CopyVerb.ico"
Friend Sub New(ByVal serverClickHandler As WebPartEventHandler)
MyBase.New("MyVerb", serverClickHandler)
End Sub
Public Overrides Property [Text]() As String
Get
Return "Copy Web Part"
End Get
Set(ByVal value As String)
End Set
End Property
Public Overrides Property Description() As String
Get
Return "This verb will copy this web part control to a " _
& "new one below"
End Get
Set(ByVal value As String)
End Set
End Property
Public Overrides Property Enabled() As Boolean
Get
Return MyBase.Enabled
End Get
Set(ByVal value As Boolean)
MyBase.Enabled = value
End Set
End Property
Public Overrides Property ImageUrl() As String
Get
Return Me._copyWebPartImageUrl
End Get
Set(ByVal value As String)
End Set
End Property
End Class
End Namespace
코드 예제의 세 번째 부분은 파생 영역 및 WebPart 컨트롤을 호스트하는 웹 페이지입니다. 페이지 Register
위쪽에는 파생 영역 구성 요소를 참조하는 지시문이 있습니다. 브라우저에서 페이지를 로드하면 컨트롤이 WebPart 영역에 나타납니다. 동사 메뉴를 클릭한 다음 CopyWebPart 동사를 클릭하면 컨트롤의 복사본이 만들어집니다.
<%@ Page Language="C#" %>
<%@ Register TagPrefix="verbsample"
namespace="Samples.AspNet.CS.Controls" %>
<!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">
<asp:WebPartManager ID="WebPartManager1" runat="server" />
<verbsample:ZoneWithAddedVerb id="ZoneWithAddedVerb1"
HeaderText="Zone with Added Verb" runat="server">
<ZoneTemplate>
<verbsample:SimpleControl id="SimpleControl1"
title="Simple Control" runat="server" />
</ZoneTemplate>
</verbsample:ZoneWithAddedVerb>
</form>
</body>
</html>
<%@ Page Language="VB" %>
<%@ Register TagPrefix="verbsample"
namespace="Samples.AspNet.VB.Controls" %>
<!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">
<asp:WebPartManager ID="WebPartManager1" runat="server" />
<verbsample:ZoneWithAddedVerb id="ZoneWithAddedVerb1"
HeaderText="Zone with Added Verb" runat="server">
<ZoneTemplate>
<verbsample:SimpleControl id="SimpleControl1"
title="Simple Control" runat="server" />
</ZoneTemplate>
</verbsample:ZoneWithAddedVerb>
</form>
</body>
</html>
설명
파생 WebPartZoneBase 영역 클래스에서 메서드를 OnCreateVerbs 재정의하여 영역의 표준 동사 컬렉션에 개체를 추가할 WebPartVerb 수 있습니다. 이 작업은 속성의 컬렉션 Verbs 에 동사를 추가하여 수행할 수 있습니다.
적용 대상
추가 정보
.NET