Share via


AssetUrlSelector.GetClientLaunchPickerReference Method

Generates a client JavaScript string that opens the Asset Picker dialog box with the configuration specified by the properties of this control.

Namespace:  Microsoft.SharePoint.Publishing.WebControls
Assembly:  Microsoft.SharePoint.Publishing (in Microsoft.SharePoint.Publishing.dll)

Syntax

'Declaration
Public Function GetClientLaunchPickerReference As String
'Usage
Dim instance As AssetUrlSelector
Dim returnValue As String

returnValue = instance.GetClientLaunchPickerReference()
public string GetClientLaunchPickerReference()

Return Value

Type: System.String
A client JavaScript string that opens the Asset Picker dialog box with the configuration specified by the properties of this control.

Exceptions

Exception Condition
NullReferenceException

A Null reference exception is thrown if the Page and ID properties of this control is not set to a valid System.Web.UI.Page object for registering the required JavaScript. Either add the control into a control collection on the page or directly set the Page and ID properties.

Remarks

The current value passed to the Asset Picker dialog box is determined from the AssetUrl property value or the AssetUrlClientID property value You can use this method if the Asset Picker dialog box is launched from an HTML element other than the provided button. You can set properties on this control, and the Visible, AssetPickerButtonVisible(), or AssetUrlTextBoxVisible() properties can be set to false. You can use the JavaScript string returned from this function in an HTML element client onclick function or an emitted JavaScript block to launch the Asset Picker dialog box.

The GetClientLaunchPickerReference method must be called before or during the OnPreRender phase of the page life cycle and you must set properties before calling this method is, in order to register the correct client JavaScript on the page. Any changes to the control's properties after the call to the GetClientLaunchPickerReference method does not affect the Asset Picker dialog box behavior because the client script controlling the dialog box is already registered on the page.

Examples

            // 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 register script in the page
            assetSelector.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 JavaScript to perform after populating the text boxes with the returned values
            assetSelector.ClientCallback = ScriptClientCallback;


            string clientLaunchPickerScript;
            if(launchPickerWithCurrentBrowserUrl)
            {
                // Use a client launch script that calculates
                // the current asset url with custom JavaScript
                // that in this sample is always 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 boxes
            assetUrlControl.Attributes["ondblclick"] = clientLaunchPickerScript + "; return false;";
            assetTextControl.Attributes["ondblclick"] = clientLaunchPickerScript + "; return false;";

            // Return the client launch script which can be added to other javascript on the page
            return clientLaunchPickerScript;

See Also

Reference

AssetUrlSelector Class

AssetUrlSelector Members

GetClientLaunchPickerReference Overload

Microsoft.SharePoint.Publishing.WebControls Namespace

AssetTextClientID

AutoPostBack

ClientCallback

AssetUrlSelector