TButton creates a click button on the page. You can create either a submit button or a command button.
A command button has a command name (specified by the CommandName property) and a command parameter (specified by CommandParameter property) associated with the button. This allows you to create multiple TButton components on a Web page and programmatically determine which one is clicked with what parameter. You can provide an event handler for the OnCommand event to programmatically control the actions performed when the command button is clicked. In the event handler, you can also determine the CommandName property value and the CommandParameter property value through name and parameter of the event parameter which is of type TCommandEventParameter.
A submit button does not have a command name associated with the button and clicking on it simply posts the Web page back to the server. By default, a TButton component is a submit button. You can provide an event handler for the OnClick event to programmatically control the actions performed when the submit button is clicked.
Note, Text will be HTML encoded before it is displayed in the TButton component. If you don't want it to be so, set EncodeText to false.
Namespace: System.Web.UI.WebControls
Properties
Text, string, kept in viewstate
Gets or sets the text caption displayed in the TButton component.
EncodeText, boolean, default=true, kept in viewstate
Gets or sets the value indicating whether Text should be HTML-encoded when rendering.
CausesValidation, boolean, default=true, kept in viewstate
Gets or sets a value indicating whether validation is performed when the TButton component is clicked.
CommandName, string, kept in viewstate
Gets or sets the command name associated with the TButton component that is passed to
the OnCommand event.
CommandParameter, string, kept in viewstate
Gets or sets an optional parameter passed to the OnCommand event along with
the associated CommandName.
Events
OnClick Occurs when the TButton component is clicked.
OnCommand Occurs when the TButton component is clicked.
Examples
On a page template file, insert the following line to create a TButton component,
The button will show "Start Game" caption on it and if the user clicks on the button, the startGame() method of the page class will be invoked automatically.
This method is invoked when the component is clicked.
The method raises 'OnClick' event to fire up the event delegates. If you override this method, be sure to call the parent implementation so that the event delegates can be invoked.
This method is invoked when the component is clicked.
The method raises 'OnCommand' event to fire up the event delegates. If you override this method, be sure to call the parent implementation so that the event delegates can be invoked.
The implementation of this function should raise appropriate event(s) (e.g. OnClick, OnCommand) indicating the component is responsible for the postback event. This method is primarily used by framework developers.