แก้ไข

แชร์ผ่าน


Button.UseSubmitBehavior Property

Definition

Gets or sets a value indicating whether the Button control uses the client browser's submit mechanism or the ASP.NET postback mechanism.

public:
 virtual property bool UseSubmitBehavior { bool get(); void set(bool value); };
[System.Web.UI.Themeable(false)]
public virtual bool UseSubmitBehavior { get; set; }
[<System.Web.UI.Themeable(false)>]
member this.UseSubmitBehavior : bool with get, set
Public Overridable Property UseSubmitBehavior As Boolean

Property Value

true if the control uses the client browser's submit mechanism; otherwise, false. The default is true.

Attributes

Examples

The following code example demonstrates how to use the UseSubmitBehavior property to specify the submit mechanism that a Button control uses when it posts back to the server. The UseSubmitBehavior property is set to false, causing the button to use the ASP.NET postback mechanism. If you view the source code for the rendered page using your browser's View Source command, you will see that client-side script has been added by the ASP.NET page framework to post the form to the server.

<%@ page language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
  
  void SubmitBtn_Click(object sender, EventArgs e)
  {
    Message.Text = "Hello World!";    
  }

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="head1" runat="server">
  <title>Button.UseSubmitBehavior Example</title>
</head>
<body>
  <form id="form1" runat="server">

    <h3>Button.UseSubmitBehavior Example</h3> 

    Click the Submit button.
     
    <br /><br /> 

    <!--The value of the UseSubmitBehavior property
    is false. Therefore the button uses the ASP.NET 
    postback mechanism.-->
    <asp:button id="Button1"
      text="Submit"
      onclick="SubmitBtn_Click" 
      usesubmitbehavior="false"
      runat="server"/>       

    <br /><br /> 

    <asp:label id="Message" 
      runat="server"/>

  </form>
</body>
</html>
<%@ page language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
    
  Sub SubmitBtn_Click(ByVal sender As Object, ByVal e As EventArgs)
    
    Message.Text = "Hello World!"
    
  End Sub

  </script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
  <title>Button.UseSubmitBehavior Example</title>
</head>
<body>
  <form id="form1" runat="server">

    <h3>Button.UseSubmitBehavior Example</h3> 

    Click the Submit button.
      
    <br /><br /> 

    <!--The value of the UseSubmitBehavior property
    is false. Therefore the button uses the ASP.NET 
    postback mechanism.-->
    <asp:button id="Button1"
      text="Submit"
      onclick="SubmitBtn_Click" 
      usesubmitbehavior="false"
      runat="server"/>       

    <br /><br /> 

    <asp:label id="Message" 
      runat="server"/>

  </form>
</body>
</html>

Remarks

Use the UseSubmitBehavior property to specify whether a Button control uses the client browser's submit mechanism or the ASP.NET postback mechanism. By default the value of this property is true, causing the Button control to use the browser's submit mechanism. If you specify false, the ASP.NET page framework adds client-side script to the page to post the form to the server.

When the UseSubmitBehavior property is false, control developers can use the GetPostBackEventReference method to return the client postback event for the Button. The string returned by the GetPostBackEventReference method contains the text of the client-side function call and can be inserted into a client-side event handler.

This property cannot be set by themes or style sheet themes. For more information, see ThemeableAttribute and ASP.NET Themes and Skins.

Applies to

See also