asppostbacktrigger_PostBackTrigger

PostBackTrigger 類別

定義

組件:System.Web.Extensions.dll

將位於 UpdatePanel 控制項內部的控制項定義為回傳控制項。Defines a control inside a UpdatePanel control as a postback control.

本文內容

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

範例

The following example shows how to declaratively define a PostBackTrigger control for an UpdatePanel control. 在面板中, FileUpload 控制項可讓使用者上傳檔案。In the panel, a FileUpload control enables users to upload a file. 使用者必須先檢查要上傳的檔案是否存在。Users must first check whether the file to upload exists. Button呼叫事件處理常式來檢查檔案名的控制項會導致非同步回傳。The Button control that calls the event handler to check the file name causes an asynchronous postback. 不過,上 Button 傳檔案的控制項會註冊為 PostBackTrigger ,因為無法以非同步方式上傳檔案。However, the Button control that uploads the file is registered as a PostBackTrigger, because files cannot be uploaded asynchronously.

/p>

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

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;

}

PostBackTrigger Example

The upload button is defined as a PostBackTrigger.

FileUpload in an UpdatePanel

First, enter a file name to upload your file to:

Then, browse and find the file to upload:

runat="server">

Text="Upload file"

OnClick="UploadButton_Click"

runat="server">

runat="server" style="color:red;">

/p>

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

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

PostBackTrigger Example

The upload button is defined as a PostBackTrigger.

FileUpload in an UpdatePanel

First, enter a file name to upload your file to:

Then, browse and find the file to upload:

runat="server">

Text="Upload file"

OnClick="UploadButton_Click"

runat="server">

runat="server" style="color:red;">

備註

使用 PostBackTrigger 控制項可讓內的控制項 UpdatePanel 導致回傳,而不是執行非同步回傳。Use the PostBackTrigger control to enable controls inside an UpdatePanel to cause a postback instead of performing an asynchronous postback.

Use the RegisterPostBackControl method of the ScriptManager control to programmatically register a postback control. 然後, Update UpdatePanel 當觸發程式控制項執行回傳時,您就可以呼叫控制項的方法。You can then call the Update method of the UpdatePanel control when the trigger control performs a postback.

注意

不支援以程式設計方式加入 PostBackTrigger 控制項。Programmatically adding PostBackTrigger controls is not supported.

If a control is set as both a PostBackTrigger and AsyncPostBackTrigger control, an exception is thrown.

建構函式

Initializes a new instance of the PostBackTrigger class.

屬性

Gets or sets the name of the control that is an PostBackTrigger control for an UpdatePanel control.

方法

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(繼承來源 Object)

搜尋在 ControlID 屬性中指定的控制項。Searches for the control specified in the ControlID property.

(繼承來源 UpdatePanelControlTrigger)

做為預設雜湊函式。Serves as the default hash function.

(繼承來源 Object)

取得目前執行個體的 Type。Gets the Type of the current instance.

(繼承來源 Object)

傳回值以指出是否要啟動觸發程序。Returns a value that indicates whether the trigger was activated.

建立目前 Object 的淺層複製。Creates a shallow copy of the current Object.

(繼承來源 Object)

Returns a string that represents the current PostBackTrigger object.

適用於

另請參閱

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值