AssetUrlSelector - Classe
Génère le rendu d'un champ d'entrée HTML et un bouton ou génère ECMAScript qui ouvre la boîte de dialogue Sélecteur d'actifs permet de sélectionner une URL de lien ou une image à partir d'une collection de sites.
Hiérarchie d’héritage
System.Object
System.Web.UI.Control
System.Web.UI.WebControls.WebControl
Microsoft.SharePoint.Publishing.WebControls.AssetUrlSelector
Espace de noms : Microsoft.SharePoint.Publishing.WebControls
Assembly : Microsoft.SharePoint.Publishing (dans Microsoft.SharePoint.Publishing.dll)
Syntaxe
'Déclaration
<ValidationPropertyAttribute("AssetUrl")> _
<AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
<SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel := True)> _
Public NotInheritable Class AssetUrlSelector _
Inherits WebControl _
Implements INamingContainer, IPostBackEventHandler, ICompositeInputControl
'Utilisation
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
Remarques
Vous pouvez utiliser un objet de cette classe comme un contrôle serveur simple qui fournit une zone de texte et d'une interface d'utilisateur navigateur bouton HTML (interface utilisateur). Vous pouvez utiliser l'objet pour sélectionner une URL qui pointe vers un objet dans la collection de sites actuelle. La propriété AssetUrl du contrôle serveur affiche la valeur actuelle de l'URL sélectionnée dans la zone de texte.
Vous pouvez personnaliser le comportement et l'apparence de la boîte de dialogue et modifier l'affichage de la zone de texte et un bouton en définissant les propriétés du contrôle. Par défaut, la boîte de dialogue Sélecteur de ressources s'ouvre pour permettre à l'utilisateur de sélectionner une URL de lien et pointe vers l'emplacement actuel de la AssetUrl ou de l'emplacement enregistré en dernier à partir de laquelle l'utilisateur a sélectionné une lien URL dans un Sélecteur de ressource. S'il n'existe aucun emplacement actuel ou stockée, puis le Sélecteur de ressource par défaut à n'importe quelle propriété DefaultOpenLocationUrl qui a été spécifiée, ou aux emplacements connus pour le site actuel et une collection de sites qui vous est présentée dans la section Rechercher dans sur le côté gauche de la boîte de dialogue Sélecteur de ressources . Par défaut, lorsque l'utilisateur sélectionne ou tape une URL dans la boîte de dialogue Sélecteur d'immobilisation et le ferme, l'URL est ajoutée à la zone de texte AssetUrlSelector .
Vous pouvez utiliser la propriété AssetUrl pour obtenir cette valeur à partir de la boîte de dialogue Sélecteur d'actif après un événement de publication (postback). Cette classe peut également être utilisée pour ouvrir la boîte de dialogue Sélecteur d'immobilisation à partir d'un élément HTML autre que le bouton fourni. Dans ce cas, vous pouvez définir la propriété Visible(), de AssetPickerButtonVisibleou de AssetUrlTextBoxVisible à false et utilisez la méthode GetClientLaunchPickerReference pour retourner une chaîne ECMAScript (JavaScript, JScript) que vous permet d'ouvrir la boîte de dialogue Sélecteur d'immobilisation avec une fonction HTML élément client onClick ou ECMAScript (JavaScript, JScript) . Vous devez appeler la méthode GetClientLaunchPickerReference avant ou pendant la phase de OnPreRender de cycle de vie de la page, et vous devez définir les propriétés avant d'appeler cette méthode pour le client approprié ECMAScript (JavaScript, JScript) à inscrire dans la page.
Les modifications apportées aux propriétés du contrôle, après l'appel de la méthode GetClientLaunchPickerReference n'affectent pas le comportement de la boîte de dialogue parce que le script client qui contrôle la boîte de dialogue est déjà inscrit dans la page. Vous pouvez instancier un objet de cette classe en l'ajoutant à la page ASPX, ou en utilisant le constructeur AssetUrlSelector et en l'ajoutant aux contrôles enfants d'un objet Control ou Page .
Exemples
Les exemples de code de cette classe peuvent être ajoutés dans n'importe quel projet Web Microsoft Visual C# de contrôle ou code-behind. Ils requièrent des références à System.Web et Microsoft.SharePoint.Publishing.
Cet exemple illustre AddVisibleAssetUrlSelectorControl et GenerateAssetUrlSelectorLaunchScript. Chaque exemple illustre les propriétés et méthodes disponibles dans cette classe.
L'exemple AddVisibleAssetUrlSelectorControl crée un contrôle AssetUrlSelector , définit ses propriétés et comportements sur événement et ajoute le contrôle à la boîte de dialogue Sélecteur de ressource .
L'exemple de GenerateAssetUrlSelectorLaunchScript crée un script qui génère un objet AssetUrlSelector et ajoute des zones de texte à une collection de contrôles sur un site.
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
Cohérence de thread
Tous les membres statique (Partagé dans Visual Basic)s publics de ce type sont thread-safe. Cela n’est pas garanti pour les membres d’instance.
Voir aussi
Référence
Microsoft.SharePoint.Publishing.WebControls - Espace de noms