Compartir a través de


Clase AssetUrlSelector

Representa un campo de entrada HTML y botón o genera ECMAScript que se abre el cuadro de diálogo Selector de activos se utiliza para seleccionar una dirección URL de vínculo o una imagen de una colección de sitios.

Jerarquía de la herencia

System.Object
  System.Web.UI.Control
    System.Web.UI.WebControls.WebControl
      Microsoft.SharePoint.Publishing.WebControls.AssetUrlSelector

Espacio de nombres:  Microsoft.SharePoint.Publishing.WebControls
Ensamblado:  Microsoft.SharePoint.Publishing (en Microsoft.SharePoint.Publishing.dll)

Sintaxis

'Declaración
<ValidationPropertyAttribute("AssetUrl")> _
<AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
<SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel := True)> _
Public NotInheritable Class AssetUrlSelector _
    Inherits WebControl _
    Implements INamingContainer, IPostBackEventHandler, ICompositeInputControl
'Uso
Dim instance As AssetUrlSelector
[ValidationPropertyAttribute("AssetUrl")]
[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
[SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel = true)]
public sealed class AssetUrlSelector : WebControl, 
    INamingContainer, IPostBackEventHandler, ICompositeInputControl

Comentarios

Puede utilizar un objeto de esta clase como un control de servidor que proporciona un cuadro de texto y una interfaz de usuario de explorador botón HTML (IU). Puede utilizar el objeto para seleccionar una dirección URL que señala a un objeto de la colección de sitios actual. La propiedad AssetUrl del control de servidor muestra el valor actual de la dirección URL seleccionada en el cuadro de texto.

Puede personalizar el comportamiento y la apariencia del cuadro de diálogo y cambiar la presentación del cuadro de texto y botón estableciendo las propiedades del control. De forma predeterminada, el cuadro de diálogo Selector de activos se abre para permitir al usuario seleccionar una dirección URL de vínculo y apunta a la ubicación actual de la AssetUrl o la ubicación almacenada en última desde el que el usuario ha seleccionado una dirección URL de vínculo en un Selector de activos. Si no hay ninguna ubicación actual o almacenada, entonces los Selector activo los valores predeterminados para cualquier propiedad de DefaultOpenLocationUrl que se ha especificado, o a las ubicaciones conocidas para el sitio actual y la colección de sitios que se presenta en la sección Buscar en el lado izquierdo del cuadro de diálogo Selector de activos . De forma predeterminada, cuando el usuario selecciona o escribe una dirección URL en el cuadro de diálogo Selector de activos y cierra, la dirección URL se agrega al cuadro de texto AssetUrlSelector .

Puede utilizar la propiedad AssetUrl para obtener este valor en el cuadro de diálogo Selector de activos después de un evento de devolución de datos. Esta clase también puede utilizarse para abrir el cuadro de diálogo Selector de activos a un elemento HTML que proporciona el botón. En este caso, puede establecer la propiedad Visible(), AssetPickerButtonVisibleo AssetUrlTextBoxVisible en false y utilice el método GetClientLaunchPickerReference para devolver una cadena de ECMAScript (JavaScript, JScript) que se puede utilizar para abrir el cuadro de diálogo Selector de activos con una función de onClick de cliente de elemento HTML o ECMAScript (JavaScript, JScript) . Debe llamar al método GetClientLaunchPickerReference antes o durante la fase de OnPreRender del ciclo de vida de página y debe establecer antes de llamar a este método para el ECMAScript (JavaScript, JScript) de cliente correcto registrar en la página de propiedades.

Los cambios realizados en las propiedades del control después de llamar al método GetClientLaunchPickerReference no afectan el comportamiento del cuadro de diálogo porque el script de cliente que esté controlando el cuadro de diálogo ya está registrado en la página. Puede crear instancias de un objeto de esta clase al agregar a la página ASPX o utilizando el constructor AssetUrlSelector y agregarlo a los controles secundarios de un objeto Control o Page .

Ejemplos

Los ejemplos de código para esta clase se pueden agregar a cualquier proyecto de código subyacente o de control Web de Microsoft Visual C#. Requieren referencias a System.Web y Microsoft.SharePoint.Publishing.

En este ejemplo se muestra AddVisibleAssetUrlSelectorControl y GenerateAssetUrlSelectorLaunchScript. Cada ejemplo muestra las propiedades y los métodos disponibles en esta clase.

  • El ejemplo AddVisibleAssetUrlSelectorControl crea un control AssetUrlSelector , define sus propiedades y comportamientos en eventos y agrega el control al cuadro de diálogo Selector de activos .

  • En el ejemplo GenerateAssetUrlSelectorLaunchScript se crea una secuencia de comandos que genera un objeto AssetUrlSelector y cuadros de texto se agrega a una colección de controles en un sitio.

using Control = System.Web.UI.Control;
using TextBox = System.Web.UI.WebControls.TextBox;
using ButtonType = System.Web.UI.WebControls.ButtonType;
using AssetUrlSelector = Microsoft.SharePoint.Publishing.WebControls.AssetUrlSelector;

namespace Microsoft.SDK.SharePointServer.Samples
{public static class AssetUrlSelectorSamples{
// You can change any of the following default const data
//  used in the AssetUrlSelector samples.

// These values control the appearance of the text box
// and button for the control
private const bool SampleAssetPickerButtonVisible = true;
private const bool SampleAssetUrlTextBoxVisible = true;
private const ButtonType SampleButtonType = ButtonType.Image;
private const string SampleCssTextBox = "sample-textbox-css";
private const string SamplePickerButtonImage = "/_layouts/images/icdoc.gif";
private const string SamplePickerButtonText = "Sample Button Text";

private const bool SampleAutoPostBack = true;
private const bool SampleDecodeUrlPath = true;
private const int SampleMaxLength = 100;
private const bool SampleValidateUrl = true;
private const bool SampleIsUrlRequired = true;
private const bool SampleAllowExternalUrls = false;

// These values control the appearance and behavior
// of the Asset Picker dialog box.
private const string SampleDefaultOpenLocationUrl = "~Site/Pages/";
private const bool SampleDefaultToLastUsedLocation = false;
private const bool SampleDisplayLookInSection = false;
private const bool SampleUseImageAssetPicker = false;
private const string SampleOverrideDialogDescription = "This is a sample description";
private const string SampleOverrideDialogFeatures = "resizable: yes; status: yes; scroll: yes; help: no; 
dialogWidth:730px; dialogHeight:500px;";
private const string SampleOverrideDialogImageUrl = "/_layouts/images/icdoc.gif";
private const string SampleOverrideDialogTitle = "Sample Selection Dialog Title";

// These values control the complex client script behaviors.
// This must be ECMAScript returning a function object.
private const string ScriptClientCallback = "function(newAssetUrl, newAssetText, 
configObject, returnedValue) { window.alert('Client callback with returned url value: ' + newAssetUrl); }";
   // This must be ECMAScript returning a string   // value for asset URL data.
private const string ScriptGetAssetUrlValue = "window.location.href";

// AddVisibleAssetUrlSelectorControl - 
// This sample constructs an AssetUrlSelector with 
// various settings and adds it to a control collection
// in a Web page.  The sample function takes in one
// required argument:
//
// containerControl: The control for which the created
// AssetUrlSelector is added as a child control
public static void AddVisibleAssetUrlSelectorControl(Control containerControl)
{if (null == containerControl){
throw new System.ArgumentNullException("containerControl", 
"The containerControl argument must not be null");}
if (null == containerControl.Page){
throw new System.ArgumentException
("The containerControl argument must be a control in a System.Web.UI.Page control tree");}
// Create the AssetUrlSelectorAssetUrlSelector assetSelector = new AssetUrlSelector();
// Set values for the appearance of the text box and // button for the control.assetSelector.AssetPickerButtonVisible = SampleAssetPickerButtonVisible;assetSelector.AssetUrlTextBoxVisible = SampleAssetUrlTextBoxVisible;assetSelector.ButtonType = SampleButtonType;assetSelector.CssTextBox = SampleCssTextBox;assetSelector.PickerButtonImage = SamplePickerButtonImage;assetSelector.PickerButtonText = SamplePickerButtonText;
// Set values for the behavior and validation// for the text box.assetSelector.AutoPostBack = SampleAutoPostBack;assetSelector.DecodeUrlPath = SampleDecodeUrlPath;assetSelector.MaxLength = SampleMaxLength;assetSelector.ValidateUrl = SampleValidateUrl;assetSelector.IsUrlRequired = SampleIsUrlRequired;assetSelector.AllowExternalUrls = SampleAllowExternalUrls;
// Set values for the appearance and behavior of the Asset Picker dialog box.assetSelector.DefaultOpenLocationUrl = SampleDefaultOpenLocationUrl;assetSelector.DefaultToLastUsedLocation = SampleDefaultToLastUsedLocation;assetSelector.DisplayLookInSection = SampleDisplayLookInSection;assetSelector.OverrideDialogDescription = SampleOverrideDialogDescription;assetSelector.OverrideDialogFeatures = SampleOverrideDialogFeatures;assetSelector.OverrideDialogImageUrl = SampleOverrideDialogImageUrl;assetSelector.OverrideDialogTitle = SampleOverrideDialogTitle;assetSelector.UseImageAssetPicker = SampleUseImageAssetPicker;
// Sets an event handler for when the AssetUrl value changes on a postback.assetSelector.AssetUrlChanged += 
delegate(object sender, System.EventArgs ev)
{ string newAssetUrlValue = ((AssetUrlSelector)sender).AssetUrl;
// Perform event handling operations based on the newAssetUrlValue. 
};
// Add the configured assetSelector to the controls on the page.containerControl.Controls.Add(assetSelector);
}

// GenerateAssetUrlSelectorLaunchScript
// This sample constructs an AssetUrlSelector with
// various settings and adds visible text boxes to a control
// collection on a Web 
// page, setting their double-click ECMAScript 
// events to open an Asset Picker dialog box. The sample function
// takes in one required argument and one optional argument:
//
// containerControl: The control for which the created
//TextBox controls are added as a child control
//
// launchPickerWithCurrentBrowserUrl: Determines
// whether the current AssetUrl property value or the
// current browser URL 
// value should be used when launching the Asset Picker.
public static string GenerateAssetUrlSelectorLaunchScript(Control containerControl,bool launchPickerWithCurrentBrowserUrl)
{if (null == containerControl){
throw new System.ArgumentNullException("containerControl", 
"The containerControl argument must not be null");}
if (null == containerControl.Page){
throw new System.ArgumentException("The containerControl argument must be a 
valid control in a System.Web.UI.Page control tree");}
TextBox assetUrlControl = new TextBox();TextBox assetTextControl = new TextBox();
// Add these text boxes to the container control so that// they get a completed ClientID property for // their container control.//  containerControl.Controls.Add(assetUrlControl);containerControl.Controls.Add(assetTextControl);
AssetUrlSelector assetSelector = new AssetUrlSelector();
// Setting the Page and ID properties is required when the// AssetUrlSelector control is not added to the page// control tree because// the AssetUrlSelector.GetClientLaunchPickerReference()// method needs to register script in the pageassetSelector.Page = containerControl.Page;assetSelector.ID = "SampleGenerateAssetUrlSelectorLaunchScript";
// Uses text box client ID to connect the Asset// Picker to the text boxes for the resulting//  URL and default text values returned from the// Asset Picker dialog box.assetSelector.AssetUrlClientID = assetUrlControl.ClientID;assetSelector.AssetTextClientID = assetTextControl.ClientID;
// Set the ECMAScript to perform after populating the text boxes // with the returned valuesassetSelector.ClientCallback = ScriptClientCallback;

string clientLaunchPickerScript;if(launchPickerWithCurrentBrowserUrl){
// Use a client launch script that calculates
// the current asset URL with custom ECMAScript
// which in this example always is the current browser location URL
clientLaunchPickerScript = assetSelector.GetClientLaunchPickerReference(ScriptGetAssetUrlValue);}else{
// Use the default client launch script that gets the
// current asset URL value based on the AssetUrlClientID
clientLaunchPickerScript = assetSelector.GetClientLaunchPickerReference();}
// Add the client launch script as an ondoubleclick handler for the two text boxesassetUrlControl.Attributes["ondblclick"] = clientLaunchPickerScript + "; return false;";assetTextControl.Attributes["ondblclick"] = clientLaunchPickerScript + "; return false;";
// Return the client launch script, which can be added to other ECMAScript on the pagereturn clientLaunchPickerScript;
}}
}
Imports Control = System.Web.UI.Control
Imports TextBox = System.Web.UI.WebControls.TextBox
Imports ButtonType = System.Web.UI.WebControls.ButtonType
Imports AssetUrlSelector = Microsoft.SharePoint.Publishing.WebControls.AssetUrlSelector

Namespace Microsoft.SDK.SharePointServer.SamplesPublic NotInheritable Class AssetUrlSelectorSamples
' You can change any of the following default const data
'  used in the AssetUrlSelector samples.

' These values control the appearance of the text box
' and button for the control
Private Const SampleAssetPickerButtonVisible As Boolean = True
Private Const SampleAssetUrlTextBoxVisible As Boolean = True
Private Const SampleButtonType As ButtonType = ButtonType.Image
Private Const SampleCssTextBox As String = "sample-textbox-css"
Private Const SamplePickerButtonImage As String = "/_layouts/images/icdoc.gif"
Private Const SamplePickerButtonText As String = "Sample Button Text"

Private Const SampleAutoPostBack As Boolean = True
Private Const SampleDecodeUrlPath As Boolean = True
Private Const SampleMaxLength As Integer = 100
Private Const SampleValidateUrl As Boolean = True
Private Const SampleIsUrlRequired As Boolean = True
Private Const SampleAllowExternalUrls As Boolean = False

' These values control the appearance and behavior
' of the Asset Picker dialog box.
Private Const SampleDefaultOpenLocationUrl As String = "~Site/Pages/"
Private Const SampleDefaultToLastUsedLocation As Boolean = False
Private Const SampleDisplayLookInSection As Boolean = False
Private Const SampleUseImageAssetPicker As Boolean = False
Private Const SampleOverrideDialogDescription As String = "This is a sample description"
Private Const SampleOverrideDialogFeatures As String = "resizable: yes; status: yes; scroll: yes; help: no; dialogWidth:730px; dialogHeight:500px;"
Private Const SampleOverrideDialogImageUrl As String = "/_layouts/images/icdoc.gif"
Private Const SampleOverrideDialogTitle As String = "Sample Selection Dialog Title"

' These values control the complex client script behaviors.
' This must be ECMAScript returning a function object.
Private Const ScriptClientCallback As String = "function(newAssetUrl, newAssetText, configObject, returnedValue) { window.alert('Client callback with returned url value: ' + newAssetUrl); }"
   ' This must be ECMAScript returning a string   ' value for asset URL data.
Private Const ScriptGetAssetUrlValue As String = "window.location.href"

' AddVisibleAssetUrlSelectorControl - 
' This sample constructs an AssetUrlSelector with 
' various settings and adds it to a control collection
' in a Web page.  The sample function takes in one
' required argument:
'
' containerControl: The control for which the created
' AssetUrlSelector is added as a child control
Private Sub New()
End Sub
Public Shared Sub AddVisibleAssetUrlSelectorControl(ByVal containerControl As Control)If Nothing Is containerControl Then
Throw New System.ArgumentNullException("containerControl", "The containerControl argument must not be null")End If
If Nothing Is containerControl.Page Then
Throw New System.ArgumentException ("The containerControl argument must be a control in a System.Web.UI.Page control tree")End If
' Create the AssetUrlSelectorDim assetSelector As New AssetUrlSelector()
' Set values for the appearance of the text box and ' button for the control.assetSelector.AssetPickerButtonVisible = SampleAssetPickerButtonVisibleassetSelector.AssetUrlTextBoxVisible = SampleAssetUrlTextBoxVisibleassetSelector.ButtonType = SampleButtonTypeassetSelector.CssTextBox = SampleCssTextBoxassetSelector.PickerButtonImage = SamplePickerButtonImageassetSelector.PickerButtonText = SamplePickerButtonText
' Set values for the behavior and validation' for the text box.assetSelector.AutoPostBack = SampleAutoPostBackassetSelector.DecodeUrlPath = SampleDecodeUrlPathassetSelector.MaxLength = SampleMaxLengthassetSelector.ValidateUrl = SampleValidateUrlassetSelector.IsUrlRequired = SampleIsUrlRequiredassetSelector.AllowExternalUrls = SampleAllowExternalUrls
' Set values for the appearance and behavior of the Asset Picker dialog box.assetSelector.DefaultOpenLocationUrl = SampleDefaultOpenLocationUrlassetSelector.DefaultToLastUsedLocation = SampleDefaultToLastUsedLocationassetSelector.DisplayLookInSection = SampleDisplayLookInSectionassetSelector.OverrideDialogDescription = SampleOverrideDialogDescriptionassetSelector.OverrideDialogFeatures = SampleOverrideDialogFeaturesassetSelector.OverrideDialogImageUrl = SampleOverrideDialogImageUrlassetSelector.OverrideDialogTitle = SampleOverrideDialogTitleassetSelector.UseImageAssetPicker = SampleUseImageAssetPicker
' Sets an event handler for when the AssetUrl value changes on a postback.AddHandler assetSelector.AssetUrlChanged, Sub(sender As Object, ev As System.EventArgs) Dim newAssetUrlValue As String = (CType(sender, AssetUrlSelector)).AssetUrl
' Add the configured assetSelector to the controls on the page.containerControl.Controls.Add(assetSelector)
End Sub

' GenerateAssetUrlSelectorLaunchScript
' This sample constructs an AssetUrlSelector with
' various settings and adds visible text boxes to a control
' collection on a Web 
' page, setting their double-click ECMAScript 
' events to open an Asset Picker dialog box. The sample function
' takes in one required argument and one optional argument:
'
' containerControl: The control for which the created
'TextBox controls are added as a child control
'
' launchPickerWithCurrentBrowserUrl: Determines
' whether the current AssetUrl property value or the
' current browser URL 
' value should be used when launching the Asset Picker.
Public Shared Function GenerateAssetUrlSelectorLaunchScript(ByVal containerControl As Control, ByVal launchPickerWithCurrentBrowserUrl As Boolean) As StringIf Nothing Is containerControl Then
Throw New System.ArgumentNullException("containerControl", "The containerControl argument must not be null")End If
If Nothing Is containerControl.Page Then
Throw New System.ArgumentException("The containerControl argument must be a valid control in a System.Web.UI.Page control tree")End If
Dim assetUrlControl As New TextBox()Dim assetTextControl As New TextBox()
' Add these text boxes to the container control so that' they get a completed ClientID property for ' their container control.'  containerControl.Controls.Add(assetUrlControl)containerControl.Controls.Add(assetTextControl)
Dim assetSelector As New AssetUrlSelector()
' Setting the Page and ID properties is required when the' AssetUrlSelector control is not added to the page' control tree because' the AssetUrlSelector.GetClientLaunchPickerReference()' method needs to register script in the pageassetSelector.Page = containerControl.PageassetSelector.ID = "SampleGenerateAssetUrlSelectorLaunchScript"
' Uses text box client ID to connect the Asset' Picker to the text boxes for the resulting'  URL and default text values returned from the' Asset Picker dialog box.assetSelector.AssetUrlClientID = assetUrlControl.ClientIDassetSelector.AssetTextClientID = assetTextControl.ClientID
' Set the ECMAScript to perform after populating the text boxes ' with the returned valuesassetSelector.ClientCallback = ScriptClientCallback

Dim clientLaunchPickerScript As StringIf launchPickerWithCurrentBrowserUrl Then
' Use a client launch script that calculates
' the current asset URL with custom ECMAScript
' which in this example always is the current browser location URL
clientLaunchPickerScript = assetSelector.GetClientLaunchPickerReference(ScriptGetAssetUrlValue)Else
' Use the default client launch script that gets the
' current asset URL value based on the AssetUrlClientID
clientLaunchPickerScript = assetSelector.GetClientLaunchPickerReference()End If
' Add the client launch script as an ondoubleclick handler for the two text boxesassetUrlControl.Attributes("ondblclick") = clientLaunchPickerScript & "; return false;"assetTextControl.Attributes("ondblclick") = clientLaunchPickerScript & "; return false;"
' Return the client launch script, which can be added to other ECMAScript on the pageReturn clientLaunchPickerScript
End FunctionEnd Class
End Namespace

Seguridad para subprocesos

Los miembros static (Shared en Visual Basic) públicos de este tipo son seguros para subprocesos. No se garantiza que los miembros de instancias sean seguros para los subprocesos.

Vea también

Referencia

Miembros AssetUrlSelector

Espacio de nombres Microsoft.SharePoint.Publishing.WebControls

AssetUrl

AssetUrlTextBoxVisible

AssetUrlClientID

AssetPickerButtonVisible

DefaultOpenLocationUrl