YouTip LogoYouTip

Prop Webcontrol Button Usesubmitbehavior

## ASP.NET Web Control: Button UseSubmitBehavior Property The `UseSubmitBehavior` property is a key configuration option for the ASP.NET Web Forms `Button` control. It determines whether the button utilizes the browser's native HTML submit mechanism or relies on the ASP.NET postback framework to submit the form. --- ## Definition and Usage By default, an ASP.NET `Button` control renders as an `` element in the browser. However, you can change this behavior using the `UseSubmitBehavior` property: * **`true` (Default):** The button uses the browser's native submission mechanism. It renders as ``. * **`false`:** The button uses the ASP.NET postback mechanism. It renders as `` and injects client-side JavaScript (specifically, the `__doPostBack` function) to trigger the form submission. ### Why set `UseSubmitBehavior` to `false`? When set to `false`, ASP.NET generates client-side script to handle the postback. This is particularly useful for control developers who want to intercept or customize the postback process. When this property is `false`, you can use the `ClientScriptManager.GetPostBackEventReference` method to retrieve the client-side script reference that initiates the postback. This script can then be embedded into other client-side event handlers (such as `onclick` or `onmouseover`). --- ## Syntax ```xml ``` --- ## Code Example The following example demonstrates how to configure an ASP.NET Button to use the ASP.NET postback mechanism instead of the browser's default submit behavior. ```aspx <%@ Page Language="VB" %> ASP.NET Button UseSubmitBehavior Example

Click the button below to trigger a postback:



``` ### How the Rendered HTML Changes: * **When `UseSubmitBehavior="true"` (Default):** ```html ``` * **When `UseSubmitBehavior="false"`:** ```html ``` --- ## Key Considerations 1. **Client-Side Validation:** If you are using ASP.NET Validation Controls (like `RequiredFieldValidator`), setting `UseSubmitBehavior="false"` automatically integrates with the client-side validation script. The postback script will only execute if the page passes client-side validation. 2. **Performance:** Native browser submission (`true`) is slightly faster as it does not require generating and executing extra client-side JavaScript for the submission process. 3. **Enter Key Behavior:** In many browsers, pressing the "Enter" key inside a text field automatically triggers the first `` on the page. If you set `UseSubmitBehavior="false"`, the button renders as ``, which may alter this default "Enter-to-submit" behavior.
← Prop Webcontrol Button ValidatProp Webcontrol Button Text β†’