ImageButton.PostBackUrl 속성

정의

ImageButton 컨트롤을 클릭했을 때 현재 페이지에서 게시할 웹 페이지의 URL을 가져오거나 설정합니다.

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

속성 값

String

ImageButton 컨트롤을 클릭했을 때 현재 페이지에서 게시할 웹 페이지의 URL입니다. 기본값은 빈 문자열("")이며, 이 경우 페이지가 자신에게 포스트백됩니다.

구현

특성

예제

다음 코드 예제에서는 크로스 페이지 게시물을 수행 하려면 속성을 사용 PostBackUrl 하는 방법을 보여 줍니다. 사용자가 컨트롤을 ImageButton 클릭하면 텍스트 상자에 입력한 값이 속성에 지정된 대상 페이지에 게시됩니다 PostBackUrl . 이 샘플을 실행하려면 이 코드 예제와 동일한 디렉터리에 대상 페이지에 대한 파일도 만들어야 합니다. 대상 페이지의 코드는 다음 예제에서 제공됩니다.

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<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>
<%@ page language="VB"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<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.PreviousPage 다른 페이지에서 게시 된 값에 액세스 하는 속성을 사용 하는 방법을 보여 줍니다 PostBackUrl . 이 페이지는 이전 페이지에서 게시된 문자열을 가져오고 사용자에게 표시합니다. 이 코드 예제를 직접 실행하려고 하면 필드 nullText 이 되므로 오류가 발생합니다. 대신 이 코드를 사용하여 대상 페이지를 만들고 이전 예제의 코드와 동일한 디렉터리에 파일을 배치합니다. 파일 이름은 이전 예제의 속성에 지정된 값에 PostBackUrl 해당해야 합니다. 이전 예제에 대한 코드를 실행하면 페이지 간 게시물이 발생할 때 이 페이지가 자동으로 실행됩니다.

참고

다음 코드 샘플 단일 파일 코드 모델을 사용 하 고 코드 숨김 파일에 직접 복사 하는 경우 제대로 작동 하지 않을 수 있습니다. 이 코드 샘플.aspx 확장명이 있는 빈 텍스트 파일에 복사 해야 합니다. Web Forms 코드 모델에 대 한 자세한 내용은 참조 하세요. ASP.NET Web Forms 페이지 코드 모델합니다.

<%@ 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 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 xmlns="http://www.w3.org/1999/xhtml" >
<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="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 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 xmlns="http://www.w3.org/1999/xhtml" >
<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>

설명

PostBackUrl 속성을 사용하면 컨트롤을 사용하여 페이지 간 게시물을 수행할 수 있습니다 ImageButton . 컨트롤을 PostBackUrl 클릭할 때 게시할 웹 페이지의 URL로 ImageButton 속성을 설정합니다. 예를 들어 지정하면 Page2.aspx 컨트롤이 포함된 ImageButton 페이지가 게시됩니다 Page2.aspx. 속성 값을 PostBackUrl 지정하지 않으면 페이지가 다시 자체에 게시됩니다.

중요

서버 쪽 유효성 검사를 사용하여 컨트롤을 사용하여 페이지 간 포스트백을 수행하는 경우 포스트백을 처리하기 전에 페이지의 IsValid 속성이 true 있는지 확인해야 합니다. 페이지 간 포스트백의 경우 확인할 페이지는 PreviousPage입니다. 다음 Visual Basic 코드는 이 작업을 수행하는 방법을 보여줍니다.

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 Forms 페이지 간 게시를 참조하세요.

이 속성은 테마 또는 스타일시트 테마에 의해 설정될 수 없습니다. 자세한 내용은 ThemeableAttribute 하 고 ASP.NET 테마 및 스킨합니다.

적용 대상

추가 정보