1

例如这个AsyncFileUpload,有一个事件“OnClientUploadComplete”

我可以做类似的事情吗

$("#ctl00_MainContent_AsyncFileUpload1_ctl02")
.bind("OnClientUploadComplete", function () {  alert("test"); 
 })
<ajaxToolkit:AsyncFileUpload  OnClientUploadComplete="uploadComplete" 
    runat="server" ID="upload"
Width="400px" UploaderStyle="Modern" CompleteBackColor="White" UploadingBackColor="#CCFFFF"
ThrobberID="imgLoader" OnUploadedComplete="AsyncFileUpload1_UploadedComplete" 
    OnClientUploadStarted = "uploadStarted" />
 <asp:Image ID="imgLoader" runat="server" ImageUrl="~/images/loader.gif" /><br /><br />
 <img id = "imgDisplay" alt="" src="" style = "display:none"/>

$addHandler($("#<%=upload.ClientID %>"), 'uploadComplete', (function () { alert("test"); }));


function uploadStarted() {
    $get("imgDisplay").style.display = "none";
}
function uploadComplete(sender, args) {
    var imgDisplay = $get("imgDisplay");
    imgDisplay.src = "images/loader.gif";
    imgDisplay.style.cssText = "";
    var img = new Image();
    img.onload = function () {
        imgDisplay.style.cssText = "height:100px;width:100px";
        imgDisplay.src = img.src;
    };
    img.src = "<%=ResolveUrl(UploadFolderPath) %>" + args.get_fileName();
} </script>
4

1 回答 1

0

不,你不能这样做。

AJAX 控件工具包中的自定义事件是在浏览器的事件系统之外实现的。有关详细信息,请参见此处

您将不得不使用add_uploadComplete()组件提供的方法:

$find("yourBehaviorID").add_uploadComplete(function() {
    alert("test").
});

yourBehaviorID您的扩展器在哪里BehaviorID(默认为ClientID扩展控件的)。

于 2012-07-31T10:36:57.027 回答