PostBackTrigger 클래스

정의

UpdatePanel 안에 있는 컨트롤을 포스트백 컨트롤로 정의합니다.

public ref class PostBackTrigger : System::Web::UI::UpdatePanelControlTrigger
public class PostBackTrigger : System.Web.UI.UpdatePanelControlTrigger
type PostBackTrigger = class
    inherit UpdatePanelControlTrigger
Public Class PostBackTrigger
Inherits UpdatePanelControlTrigger
상속

예제

다음 예제에서는 선언적으로 정의 하는 방법을 보여 줍니다는 PostBackTrigger 제어는 UpdatePanel 제어 합니다. 패널에서는 FileUpload 컨트롤을 사용 하면 파일을 업로드 합니다. 사용자가 업로드할 파일의 존재 여부 확인 먼저 해야 합니다. Button 비동기 포스트백을 발생 하는 파일 이름을 확인 하려면 이벤트 처리기를 호출 하는 컨트롤입니다. 그러나 합니다 Button 파일을 업로드 하는 컨트롤이으로 등록 되었는지는 PostBackTrigger이므로 파일을 비동기적으로 업로드할 수 없습니다.

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

    private string saveDir = @"Uploads\";
    
    protected void UploadButton_Click(object sender, EventArgs e)
    {
        if (FileUpload1.HasFile && FileUpload1.FileBytes.Length < 10000 &&
            !CheckForFileName())
        {
            string savePath = Request.PhysicalApplicationPath + saveDir +
                Server.HtmlEncode(FileName.Text);
            //Remove comment from the next line to upload file.
            //FileUpload1.SaveAs(savePath);
            UploadStatusLabel.Text = "The file was processed successfully.";
        }
        else
        {
            UploadStatusLabel.Text = "You did not specify a file to upload, or a file name, or the file was too large. Please try again.";
        }
    }

    protected void CheckButton_Click(object sender, EventArgs e)
    {
        if (FileName.Text.Length > 0)
        {
            string s = CheckForFileName() ? "exists already." : "does not exist.";
            UploadStatusLabel.Text = "The file name choosen " + s;
        }
        else
        {
            UploadStatusLabel.Text = "Specify a file name to check.";
        }
    }
    private Boolean CheckForFileName()
    {
        System.IO.FileInfo fi = new System.IO.FileInfo(Request.PhysicalApplicationPath + 
            saveDir + Server.HtmlEncode(FileName.Text));
            return fi.Exists;
    }

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>PostBackTrigger Example</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:ScriptManager ID="ScriptManager1" runat="server" />
    The upload button is defined as a PostBackTrigger.<br/>
    <asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" runat="server">
    <ContentTemplate>
    <fieldset>
    <legend>FileUpload in an UpdatePanel</legend>
       First, enter a file name to upload your file to: 
       <asp:TextBox ID="FileName" runat="server" />
       <asp:Button ID="CheckButton" Text="Check" runat="server" OnClick="CheckButton_Click" />
       <br />
       Then, browse and find the file to upload:
       <asp:FileUpload id="FileUpload1"                 
           runat="server">
       </asp:FileUpload>
       <br />
       <asp:Button id="UploadButton" 
           Text="Upload file"
           OnClick="UploadButton_Click"
           runat="server">
       </asp:Button>    
       <br />
       <asp:Label id="UploadStatusLabel"
           runat="server" style="color:red;">
       </asp:Label>           
    </fieldset>
    </ContentTemplate>
    <Triggers>
    <asp:PostBackTrigger ControlID="UploadButton" />
    </Triggers>
    </asp:UpdatePanel>
    </div>
    </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">

    Private saveDir As String = "Uploads\\"

    Protected Sub UploadButton_Click(ByVal sender As Object, ByVal e As EventArgs)
        
        If (FileUpload1.HasFile AndAlso FileUpload1.FileBytes.Length < 10000 AndAlso _
           Not (CheckForFileName())) Then
            Dim savePath As String = Request.PhysicalApplicationPath & saveDir & _
               Server.HtmlEncode(FileName.Text)
            'Remove comment from the next line to upload file.
            'FileUpload1.SaveAs(savePath)
            UploadStatusLabel.Text = "The file was processed successfully."
        Else
            UploadStatusLabel.Text = "You did not specify a file to upload, or a file name, or the file was too large. Please try again."
        End If
        
    End Sub

    Protected Sub CheckButton_Click(ByVal sender As Object, ByVal e As EventArgs)
        If (FileName.Text.Length > 0) Then
            Dim s As String
            If (CheckForFileName()) Then
                s = "exists already."
            Else
                s = "does not exist."
            End If
            UploadStatusLabel.Text = "The file name choosen " & s
        Else
            UploadStatusLabel.Text = "Specify a file name to check."
        End If
    End Sub

    Private Function CheckForFileName() As Boolean
        Dim fi As New System.IO.FileInfo(Request.PhysicalApplicationPath & _
           saveDir & Server.HtmlEncode(FileName.Text))
        Return fi.Exists
    End Function

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>PostBackTrigger Example</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:ScriptManager ID="ScriptManager1" runat="server" />
    The upload button is defined as a PostBackTrigger.<br/>
    <asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" runat="server">
    <ContentTemplate>
    <fieldset>
    <legend>FileUpload in an UpdatePanel</legend>
       First, enter a file name to upload your file to: 
       <asp:TextBox ID="FileName" runat="server" />
       <asp:Button ID="CheckButton" Text="Check" runat="server" OnClick="CheckButton_Click" />
       <br />
       Then, browse and find the file to upload:
       <asp:FileUpload id="FileUpload1"                 
           runat="server">
       </asp:FileUpload>
       <br />
       <asp:Button id="UploadButton" 
           Text="Upload file"
           OnClick="UploadButton_Click"
           runat="server">
       </asp:Button>    
       <br />
       <asp:Label id="UploadStatusLabel"
           runat="server" style="color:red;">
       </asp:Label>           
    </fieldset>
    </ContentTemplate>
    <Triggers>
    <asp:PostBackTrigger ControlID="UploadButton" />
    </Triggers>
    </asp:UpdatePanel>
    </div>
    </form>
</body>
</html>

설명

사용 하 여는 PostBackTrigger 컨트롤 내에 있는 컨트롤을 사용 하도록 설정 하는 UpdatePanel 비동기 포스트백을 수행 하는 대신 포스트백을 발생 하 합니다.

사용 된 RegisterPostBackControl 메서드의 ScriptManager 포스트백 컨트롤을 프로그래밍 방식으로 등록할 컨트롤입니다. 호출할 수 있습니다는 Update 메서드는 UpdatePanel 트리거 컨트롤이 포스트백을 수행 하는 경우를 제어 합니다.

참고

프로그래밍 방식으로 추가 PostBackTrigger 컨트롤은 지원 되지 않습니다.

컨트롤은 둘 다로 설정 하는 경우는 PostBackTriggerAsyncPostBackTrigger 컨트롤 예외가 throw 됩니다.

생성자

PostBackTrigger()

PostBackTrigger 클래스의 새 인스턴스를 초기화합니다.

속성

ControlID

PostBackTrigger 컨트롤의 UpdatePanel 컨트롤 역할을 하는 컨트롤의 이름을 가져오거나 설정합니다.

Owner

UpdatePanel의 대상이 되는 UpdatePanelTrigger 컨트롤에 대한 참조를 가져옵니다.

(다음에서 상속됨 UpdatePanelTrigger)

메서드

Equals(Object)

지정된 개체가 현재 개체와 같은지 확인합니다.

(다음에서 상속됨 Object)
FindTargetControl(Boolean)

ControlID 속성에 지정된 컨트롤을 찾습니다.

(다음에서 상속됨 UpdatePanelControlTrigger)
GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
HasTriggered()

트리거가 활성화되었는지 여부를 나타내는 값을 반환합니다.

Initialize()

초기화는 PostBackTrigger 개체입니다.

MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
ToString()

현재 PostBackTrigger 개체를 나타내는 문자열을 반환합니다.

적용 대상

추가 정보