Version: 1.1 | 2.0 |

Button

in namespace DotVVM.BusinessPack.Controls

Renders the HTML button that is able to trigger a postback.

Properties

Name Type Description Notes Default Value
AutoFocus Boolean Gets or sets whether the control should have focus when page loads or when a dialog is opened. The default value is false.
attribute
inner element
static value
bindable
default
False
ButtonTagName ButtonTagName
attribute
inner element
static value
bindable
default
input
Enabled Boolean
attribute
inner element
static value
bindable
default
False
IsSubmitButton Boolean
attribute
inner element
static value
bindable
default
False
TabIndex Int32 Gets or sets the order in which the control is reachable in sequential keyboard navigation. The default value is 0 which means the document order.
attribute
inner element
static value
bindable
default
0
Text String
attribute
inner element
static value
bindable
default
Type ButtonType? Gets or sets the type (color) of the Button.
attribute
inner element
static value
bindable
default

Events

Name Type Description
Click Command

Usage & Scenarios

Inherits the built-in Button control with a DotVVM Business Pack visual style.

HTML Rendered by the Control

Depending on the ButtonTagName property, the control renders one of these HTML elements:

<input type="submit" value="Text" />
<button type="submit">Text</button>

Sample 1: Basic Usage

The Button control has a Text property that holds the text displayed in the button.

In the Click event you can specify which method will be called in the viewmodel.

<p>Clicks count: {{value: ClicksCount}}</p>

<bp:Button Text="Click me!"
           Click="{command: Click()}" />
using DotVVM.Framework.ViewModel;

namespace DotvvmWeb.Views.Docs.Controls.businesspack.Button.sample1
{
    public class ViewModel : DotvvmViewModelBase
    {
        public int ClicksCount { get; set; }

        public void Click()
        {
            ClicksCount++;
        }
    }
}

Sample 2: Disable or Hide the Button

To disable or enable the button, use the Enabled property. It supports the data-binding.

It's also possible to hide the button completely by using the Visible property.

<p>Show button is enabled only when Hide button is visible.</p>

<bp:Button Text="Show Button"
           Enabled="{value: IsEnabled}"
           Click="{command: ShowButton()}" />

<bp:Button Text="Hide Button"
           Visible="{value: IsVisible}"
           Click="{command: HideButton()}" />
using DotVVM.Framework.ViewModel;

namespace DotvvmWeb.Views.Docs.Controls.businesspack.Button.sample2
{
    public class ViewModel : DotvvmViewModelBase
    {
        public bool IsEnabled { get; set; }
        public bool IsVisible { get; set; } = true;

        public void ShowButton()
        {
            IsEnabled = false;
            IsVisible = true;
        }

        public void HideButton()
        {
            IsVisible = false;
            IsEnabled = true;
        }
    }
}

Sample 3: Button Types

The Button control has the ButtonTagName property which specifies the tag rendered by the button. You can also choose whether it is a submit button or a normal button using the IsSubmitButton property.

The Type of the button cen be set to Primary, Secondary, Success, Info, Warning and Danger. It will change button's color and style.

<bp:Button Text="Button"
           ButtonTagName="button"
           Type="Info" />

<br />

<bp:Button Text="Input Button"
           ButtonTagName="input" />

<br />

<bp:Button Text="Submit Button"
           IsSubmitButton="true"
           Type="Primary" />

Sample 4: Image in the Button

The <button> tag supports more than just a text in the button. Instead of using the Text property, you can put the content inside the button.

<bp:Button ButtonTagName="button">
    <img src="~/Resources/Images/dotvvm.png" />
    <p>Custom Button with Image<p />
</bp:Button>

Suggestions


Help & Contribute

The documentation is maintained on GitHub.
We'll be happy if you edit the page and create a pull request.

Send message