ImageButton.PostBackUrl プロパティとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > ImageButton.PostBackUrl プロパティの意味・解説 

ImageButton.PostBackUrl プロパティ

メモ : このプロパティは、.NET Framework version 2.0 で新しく追加されたものです。

ImageButton コントロールがクリックされたときに現在のページからのポスト先となるページの URL を取得または設定します。

名前空間: System.Web.UI.WebControls
アセンブリ: System.Web (system.web.dll 内)
構文構文

<ThemeableAttribute(False)> _
Public Overridable Property
 PostBackUrl As String
Dim instance As ImageButton
Dim value As String

value = instance.PostBackUrl

instance.PostBackUrl = value
[ThemeableAttribute(false)] 
public virtual string PostBackUrl { get;
 set; }
[ThemeableAttribute(false)] 
public:
virtual property String^ PostBackUrl {
    String^ get ();
    void set (String^ value);
}
/** @property */
public String get_PostBackUrl ()

/** @property */
public void set_PostBackUrl (String value)
public function get PostBackUrl
 () : String

public function set PostBackUrl
 (value : String)

プロパティ値
ImageButton コントロールがクリックされたときに現在のページからのポスト先となる Web ページの URL。既定値は空の文字列 ("") です。この場合、ページはそのページ自体にポストバックされます。

解説解説

PostBackUrl プロパティを使用すると、ImageButton コントロールを使用して、ページ間ポストを実行できます。PostBackUrl プロパティに、ImageButton コントロールがクリックされたときのポスト先となる Web ページの URL を設定します。たとえば、Page2.aspx と指定すると、その ImageButton コントロールが含まれるページが Page2.aspx にポストされます。PostBackUrl プロパティの値を指定しない場合、ページはそのページ自体にポストバックされます。

メモ重要 :

サーバー側の検証を行うコントロールを使用したページ間ポストバックを実行するときは、ポストバックの処理前にページの IsValid プロパティが true であることを確認する必要があります。ページ間ポストバックの場合、チェックするページは PreviousPage です。この処理を行う VB コードを次に示します。

Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Page.PreviousPage.IsValid Then
            ' Handle the post back
        Else
            Response.Write("Invalid")
        End If
End Sub

ページ間ポスティングの手法の詳細については、「ASP.NET Web ページにおけるページ間ポスティング」を参照してください。

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

使用例使用例

PostBackUrl プロパティを使用してページ間ポストを実行する方法を次のコード例に示します。ユーザーが ImageButton コントロールをクリックすると、そのページのテキスト ボックスに入力された値が、PostBackUrl プロパティで指定されたポスト先のページにポストされます。このサンプルを実行するには、ポスト先のページのファイルもこのコード例と同じディレクトリに作成する必要があります。ポスト先のページのコードは、次の例で示します。

<%@ page language="VB"%>

<html>
<head id="Head1" runat="server">
  <title>ImageButton.PostBackUrl Example</title>
</head>
<body>    
  <form id="Form1" runat="server">
    
    <h3>ImageButton.PostBackUrl Example</h3>

    Enter a value to post:
    <asp:textbox id="TextBox1" 
      runat=Server>
    </asp:textbox>

    <br /><br />

    <asp:imagebutton id="PostImageButton"
      imageUrl="Images\PostButton.jpg"
      alternatetext="Post back to this page"
      runat="Server">
    </asp:imagebutton>

    <br /><br />

    <asp:imagebutton id="CrossPostImageButton"
      imageUrl="Images\CrossPostButton.jpg"
      alternatetext="Post value to another page" 
      postbackurl="ImageButton.PostBackUrlPage2vb.aspx"
 
      runat="Server">
    </asp:imagebutton>

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

<html>
<head id="Head1" runat="server">
  <title>ImageButton.PostBackUrl Example</title>
</head>
<body>    
  <form id="Form1" runat="server">
    
    <h3>ImageButton.PostBackUrl Example</h3>

    Enter a value to post:
    <asp:textbox id="TextBox1" 
      runat=Server>
    </asp:textbox>

    <br /><br />

    <asp:imagebutton id="ImageButton1"
      imageUrl=""
      alternatetext="Post back to this page"
      runat="Server">
    </asp:imagebutton>

    <br /><br />

    <asp:imagebutton id="ImageButton2"
      imageUrl=""
      alternatetext="Post value to another page" 
      postbackurl="ImageButton.PostBackUrlPage2cs.aspx" 
      runat="Server">
    </asp:imagebutton>

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

PostBackUrl プロパティを使用して別のページからポストされた値に、Page.PreviousPage プロパティを使用してアクセスする方法を次のコード例に示します。このページは、前のページからポストされた文字列を取得して表示します。このコード例を直接実行しようとすると、Text フィールドの値が null 参照 (Visual Basic では Nothing) となるため、エラーが発生します。代わりに、このコードを使用してポスト先のページを作成し、そのファイルを前の例のコードと同じディレクトリに配置してください。ファイルの名前は、前の例の PostBackUrl プロパティに指定した値に対応させる必要があります。前の例のコードを実行すると、ページ間ポストが行われたときに、このページが自動的に実行されます。

メモメモ

次のコード サンプルはシングルファイル コード モデルを使用しており、分離コード ファイルに直接コピーされた場合は正常に動作しない可能性があります。このコード サンプルは、拡張子が .aspx の空のテキスト ファイルにコピーする必要があります。Web フォームのコード モデルの詳細については、「ASP.NET Web ページのコード モデル」を参照してください。

<%@ page language="VB" %>

<script runat="server">
  Sub Page_Load(ByVal sender As
 System.Object, ByVal e As System.EventArgs)
    
    Dim text As String
    
    ' Get the value of TextBox1 from the page that posted
    ' to this page.
    text = CType((PreviousPage.FindControl("TextBox1")),
 TextBox).Text
       
    ' Check for an empty string.
    If Not (text = "")
 Then
      PostedLabel.Text = "The string posted from the previous
 page is " _
                         & text & "."
    Else
      PostedLabel.Text = "An empty string was posted from the
 previous page."
    End If
    
  End Sub

</script>

<html>
<head id="Head1" runat="server">
  <title>ImageButton.PostBackUrl Target Page Example</title>
</head>
<body>
  <form id="Form1" runat="server">
    
    <h3>ImageButton.PostBackUrl Target Page Example</h3>
       
    <br />
    
    <asp:label id="PostedLabel"
       runat=Server>
    </asp:label>

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

<script runat="server">
  
  void Page_Load (object sender, System.EventArgs e)
  {
    string text;
    
    // Get the value of TextBox1 from the page that 
    // posted to this page.
    text = ((TextBox)PreviousPage.FindControl("TextBox1")).Text;
    
    // Check for an empty string.
    if (text != "")
      PostedLabel.Text = "The string posted from the previous
 page is "
                         + text + ".";
    else
      PostedLabel.Text = "An empty string was posted from
 the previous page.";
  }

</script>

<html>
<head id="Head1" runat="server">
  <title>ImageButton.PostBackUrl Target Page Example</title>
</head>
<body>
  <form id="Form1" runat="server">
    
    <h3>ImageButton.PostBackUrl Target Page Example</h3>
      
    <br />
    
    <asp:label id="PostedLabel"
       runat=Server>
    </asp:label>

    </form>
</body>
</html>
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

ImageButton.PostBackUrl プロパティのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



ImageButton.PostBackUrl プロパティのページの著作権

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.

©2026 GRAS Group, Inc.RSS