Export (0) Print
Expand All
2 out of 5 rated this helpful - Rate this topic

Button.UseSubmitBehavior Property

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

Namespace: System.Web.UI.WebControls
Assembly: System.Web (in system.web.dll)

[ThemeableAttribute(false)] 
public virtual bool UseSubmitBehavior { get; set; }
/** @property */
public boolean get_UseSubmitBehavior ()

/** @property */
public void set_UseSubmitBehavior (boolean value)

public function get UseSubmitBehavior () : boolean

public function set UseSubmitBehavior (value : boolean)

Not applicable.

Property Value

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

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 Introduction to ASP.NET Themes.

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>

Windows 98, Windows Server 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.