CopyButton
in namespace DotVVM.BusinessPack.Controls
Renders the HTML button that is able to copy a value to clipboard.
Usage & Scenarios
CopyButton copies a bound value to the clipboard when clicked. Its optional Click command runs only after the copy succeeds.
Sample 1: Copying a reference number
Bind ValueToCopy to the value to copy. Edit the reference, click Copy reference, and paste into the second box to check the result. The counter advances only on a successful copy.
As with the Button, use either Text or inner content for the caption. Here Enabled prevents copying an empty reference.
<label>Reference: <bp:TextBox Text="{value: Reference}" /></label>
<bp:CopyButton Text="Copy reference" ValueToCopy="{value: Reference}"
Enabled="{value: !string.IsNullOrEmpty(Reference)}"
Click="{staticCommand: Copies = Copies + 1}" />
<p>Successful copies: {{value: Copies}}</p>
<label>Paste here: <input type="text" /></label>
using DotVVM.Framework.ViewModel;
namespace DotvvmWeb.Views.Docs.Controls.businesspack.CopyButton.sample1
{
public class ViewModel : DotvvmViewModelBase
{
public string Reference { get; set; } = "INV-1042";
public int Copies { get; set; }
}
}
Properties
| Name | Type | Description | Notes | Default Value | |
|---|---|---|---|---|---|
| ClientIDMode | ClientIDMode | Gets or sets the client ID generation algorithm. |
attribute
static value
|
Static | |
| DataContext | Object | Gets or sets a data context for the control and its children. All value and command bindings are evaluated in context of this value. The DataContext is null in client-side templates. |
attribute
bindable
|
null | |
| DisableContentStyle | Boolean |
attribute
static value
bindable
|
False | ||
| Enabled | Boolean | Gets or sets a value indicating whether the button is enabled and can be clicked on. |
attribute
static value
bindable
|
True | |
| ID | String | Gets or sets the control client ID within its naming container. |
attribute
static value
bindable
|
null | |
| IncludeInPage | Boolean | Gets or sets whether the control is included in the DOM of the page. |
attribute
static value
bindable
|
True | |
| InnerText | String | Gets or sets the inner text of the HTML element. Note that this property can only be used on HtmlGenericControl directly and when the control does not have any children. |
attribute
static value
bindable
|
null | |
| Text | String | Gets or sets the text displayed on the button. |
attribute
static value
bindable
|
||
| ValueToCopy | Object | Gets or sets the value that will be copied to clipboard when the button is clicked. The Click command is triggered after the value is successfully copied. |
attribute
bindable
|
null | |
| Visible | Boolean | Gets or sets whether the control is visible. When set to false, `style="display: none"` will be added to this control. |
attribute
static value
bindable
|
True |
Events
| Name | Type | Description | |
|---|---|---|---|
| Click | Command | Gets or sets the command triggered when the button is clicked. |