Button.PostBackUrl プロパティ
アセンブリ: System.Web (system.web.dll 内)

Dim instance As Button Dim value As String value = instance.PostBackUrl instance.PostBackUrl = value
[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)
Button コントロールがクリックされたときに現在のページからのポスト先となる Web ページの URL。既定値は空の文字列 ("") です。この場合、ページはそのページ自体にポストバックされます。

PostBackUrl プロパティを使用すると、Button コントロールを使用して、ページ間ポストを実行できます。PostBackUrl プロパティに、Button コントロールがクリックされたときのポスト先となる Web ページの URL を設定します。たとえば、Page2.aspx と指定すると、その Button コントロールが含まれるページが 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 プロパティを使用してページ間ポストを実行する方法を次のコード例に示します。ユーザーが Button コントロールをクリックすると、そのページのテキスト ボックスに入力された値が、PostBackUrl プロパティで指定されたポスト先のページにポストされます。このサンプルを実行するには、ポスト先のページのファイルもこのコード例と同じディレクトリに作成する必要があります。ポスト先のページのコードは、次の例で示します。
<%@ page language="VB" %> <html> <head id="Head1" runat="server"> <title>Button.PostBackUrl Example</title> </head> <body> <form id="Form1" runat="server"> <h3>Button.PostBackUrl Example</h3> Enter a value to post: <asp:textbox id="TextBox1" runat=Server> </asp:textbox> <br><br /> <asp:button id="Button1" text="Post back to this page" runat="Server"> </asp:button> <br /><br /> <asp:button id="Button2" text="Post value to another page" postbackurl="Button.PostBackUrlPage2vb.aspx" runat="Server"> </asp:button> </form> </body> </html>
<%@ page language="C#" %> <html> <head id="Head1" runat="server"> <title>Button.PostBackUrl Example</title> </head> <body> <form id="Form1" runat="server"> <h3>Button.PostBackUrl Example</h3> Enter a value to post: <asp:textbox id="TextBox1" runat=Server> </asp:textbox> <br><br /> <asp:button id="Button1" text="Post back to this page" runat="Server"> </asp:button> <br /><br /> <asp:button id="Button2" text="Post value to another page" postbackurl="Button.PostBackUrlPage2cs.aspx" runat="Server"> </asp:button> </form> </body> </html>
PostBackUrl プロパティを使用して別のページからポストされた値に、Page.PreviousPage プロパティを使用してアクセスする方法を次のコード例に示します。このページは、前のページからポストされた文字列を取得して表示します。このコード例を直接実行しようとすると、text フィールドの値が null 参照 (Visual Basic では Nothing) となるため、エラーが発生します。代わりに、このコードを使用してポスト先のページを作成し、そのファイルを前の例のコードと同じディレクトリに配置してください。ファイルの名前は、前の例の PostBackUrl プロパティに指定した値に対応させる必要があります。前の例のコードを実行すると、ページ間ポストが行われたときに、このページが自動的に実行されます。
<%@ 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>Button.PostBackUrl Target Page Example</title> </head> <body> <form id="Form1" runat="server"> <h3>Button.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>Button.PostBackUrl Target Page Example</title> </head> <body> <form id="Form1" runat="server"> <h3>Button.PostBackUrl Target Page Example</h3> <br /> <asp:label id="PostedLabel" runat=Server> </asp:label> </form> </body> </html>

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からButton.PostBackUrl プロパティを検索する場合は、下記のリンクをクリックしてください。

- Button.PostBackUrl プロパティのページへのリンク