Button.UseSubmitBehavior プロパティ

定義

Button コントロールがクライアント ブラウザーの送信機構を使用するのか、ASP.NET のポストバック機構を使用するのかを示す値を取得または設定します。

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

プロパティ値

コントロールがブラウザーの送信機構を使用する場合は true。それ以外の場合は false。 既定値は、true です。

属性

次のコード例では、 プロパティを UseSubmitBehavior 使用して、コントロールがサーバーにポストバックするときに使用する Button 送信メカニズムを指定する方法を示します。 UseSubmitBehaviorプロパティが にfalse設定されているため、ボタンは ASP.NET ポストバック メカニズムを使用します。 ブラウザーの [ソースの表示] コマンドを使用してレンダリングされたページのソース コードを表示すると、フォームをサーバーに投稿するために、ASP.NET ページ フレームワークによってクライアント側スクリプトが追加されていることがわかります。

<%@ 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>

注釈

プロパティを UseSubmitBehavior 使用して、コントロールで Button クライアント ブラウザーの送信メカニズムと ASP.NET ポストバック メカニズムのどちらを使用するかを指定します。 既定では、このプロパティの値は です true。これにより、 Button コントロールはブラウザーの送信メカニズムを使用します。 を指定 falseすると、ASP.NET ページ フレームワークによってクライアント側スクリプトがページに追加され、フォームがサーバーに投稿されます。

プロパティが の UseSubmitBehavior 場合、コントロール開発者は falseメソッドを GetPostBackEventReference 使用して、 のクライアント ポストバック イベントを Button返すことができます。 メソッドによって GetPostBackEventReference 返される文字列には、クライアント側の関数呼び出しのテキストが含まれており、クライアント側のイベント ハンドラーに挿入できます。

このプロパティは、テーマまたはスタイル シート テーマによって設定することはできません。 詳細については、「テーマとスキン」と「ASP.NET」を参照してくださいThemeableAttribute

適用対象

こちらもご覧ください