Button

in namespace DotVVM.Framework.Controls

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

Usage & Scenarios

This control renders HTML button which is able to trigger a postback.

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.

<dot:Button Click="{command: Calculate()}" Text="Sample Button" />

<dot:Literal Text="{value: CurrentValue}"></dot:Literal>
using DotVVM.Framework.ViewModel;

namespace DotvvmWeb.Views.Docs.Controls.builtin.Button.sample1
{
    public class ViewModel : DotvvmViewModelBase
    {
        public int CurrentValue { get; set; } = 0;

        public void Calculate()
        {
            CurrentValue++;
        }

    }
}

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.

<dot:Button Click="{command: SetVisible()}" Text="Button" Enabled="{value: Enabled}"/>

<dot:Button Click="{command: SetEnabled()}" Text="Invisible Button" Visible="{value: Visible}"/>
using DotVVM.Framework.ViewModel;

namespace DotvvmWeb.Views.Docs.Controls.builtin.Button.sample2
{
    public class ViewModel : DotvvmViewModelBase
    {

        public bool Enabled { get; set; } = true;

        public bool Visible { get; set; } = false;

        public void SetEnabled()
        {
            Enabled = true;
            Visible = false;
        }

        public void SetVisible()
        {
            Visible = true;
            Enabled = false;
        }

    }

}

Sample 3: Button Types

The Button control has the ButtonTagName property which specifies the tag rendered by the button.
Pass either input (<input ... />) or button (<button ... />) values.

You can also choose whether it is a submit button or a normal button using the IsSubmitButton property.

<dot:Button Click="{command: Calculate()}" Text="Button with Input tag" ButtonTagName="input"/>

<dot:Button Click="{command: ShowMessage()}" Text="Submit Button" IsSubmitButton="true"/>

<dot:Literal Text="{value: Message}"/>

<dot:Literal Text="Current value: "></dot:Literal><dot:Literal Text="{value: CurrentValue}"/>

<dot:Literal Text="Submitted value: "></dot:Literal><dot:Literal Text="{value: SubmittedValue}"/>
using DotVVM.Framework.ViewModel;

namespace DotvvmWeb.Views.Docs.Controls.builtin.Button.sample3
{
    public class ViewModel : DotvvmViewModelBase
    {
        public int SubmittedValue { get; set; } = 0;
        public int CurrentValue { get; set; } = 0;

        public string Message { get; set; } = "";

        public void Calculate()
        {
            CurrentValue++;
            Message = "";
        }

        public void ShowMessage()
        {
            Message = "Value submitted.";
            SubmittedValue = CurrentValue;
        }

    }
}

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.

<dot:Button ButtonTagName="button" Click="{command: Click()}">
    <img src="~/images/delete.png" alt="Delete" />
    Delete
</dot:Button>
using DotVVM.Framework.ViewModel;

namespace DotvvmWeb.Views.Docs.Controls.builtin.Button.sample3
{
    public class ViewModel : DotvvmViewModelBase
    {
        
        public void Click()
        {
        }
        
    }
}

Properties

Name Type Description Notes Default Value
property icon ButtonTagName ButtonTagName Gets or sets whether the control should render the <input> or the <button> tag in the HTML.
attribute
inner element
static value
bindable
default
0
property icon ClientIDMode ClientIDMode Gets or sets the client ID generation algorithm.
attribute
inner element
static value
bindable
default
1
property icon 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.
attribute
inner element
static value
bindable
default
null
property icon Enabled Boolean Gets or sets a value indicating whether the button is enabled and can be clicked on.
attribute
inner element
static value
bindable
default
True
property icon ID String Gets or sets the unique control ID.
attribute
inner element
static value
bindable
default
null
property icon InnerText String Gets or sets the inner text of the HTML element.
attribute
inner element
static value
bindable
default
null
property icon IsSubmitButton Boolean Gets or sets whether the control should render a submit button or a normal button (type="submit" or type="button"). The submit button has some special features in the browsers, e.g. handles the Return key in HTML forms etc.
attribute
inner element
static value
bindable
default
False
property icon Text String Gets or sets the text on the button.
attribute
inner element
static value
bindable
default
property icon Visible Boolean Gets or sets whether the control is visible.
attribute
inner element
static value
bindable
default
True

Events

Name Type Description
event icon Click Command Gets or sets the command that will be triggered when the button is clicked.

HTML produced by the control

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

<input type="submit" onclick="dotvvm.postBack(...);" value="Text" />
<button type="submit" onclick="dotvvm.postBack(...);">
	Text
</button>