问题描述
我不知道为什么调用 OnUploadedComplete
普通的方式是不行的,这是我的code内的另一个功能:
ASP.NET code:
< ASP:AsyncFileUpload ID =AsyncFileUpload1=服务器
OnUploadedComplete =UploadFile1
OnClientUploadComplete =uploadCompleteThrobberID =myThrobber
onclientuploaderror =uploadError时CompleteBackColor =白/>
VB.NET code:
保护小组UploadFile1(BYVAL发件人为对象,BYVAL E上System.EventArgs)
磁盘上的文件saveing,这部分工作正常,但调用
MyFunction的()无法正常工作
MyFunction的()
结束小组子MyFunction的()
mylabel.Text =完成这不工作
insert_records_to_db()'这个作品
结束小组
这是因为AsyncFileUpload控制在一个iframe呈现的(通常一个FileUpload只有具有完全回发,由于安全方面的原因可能),因此它不具有UpdatePanel的正常行为。
您可以通过处理客户方变通办法 OnClientUploadComplete
来触发一个隐藏按钮,导致异步回发。
OnClientUploadComplete =uploadComplete功能uploadComplete(){
$获得(<%= btnShowUploadResult.ClientID%GT;)。点击();
}< ASP:按钮的ID =btnShowUploadResult=服务器的CausesValidation =false的文本=hidden样式=显示:无/>
您可以在服务器端 OnUploadedComplete
您的信息存储到一个会话变量,并在 btnShowUploadResult.Click
读它的处理程序
I don't know why calling another function inside the OnUploadedComplete
does not work in ordinary way, It's my code:
ASP.NET code:
<asp:AsyncFileUpload ID="AsyncFileUpload1" runat="server"
OnUploadedComplete ="UploadFile1"
OnClientUploadComplete="uploadComplete" ThrobberID="myThrobber"
onclientuploaderror="uploadError" CompleteBackColor="White" />
VB.NET code:
Protected Sub UploadFile1(ByVal sender As Object, ByVal e As System.EventArgs)
'saveing file on disk, this part works fine, but calling
'myfunction() does not work properly
myfunction()
End Sub
Sub myfunction()
mylabel.Text="done" 'this does not work
insert_records_to_db() 'this works
End Sub
This is because an AsyncFileUpload-Control is rendered in an IFrame(normally a FileUpload is only possible with full postbacks due to security reasons), therefore it does not have the normal behaviour of UpdatePanels.
You can workaround it by handling the clientside OnClientUploadComplete
to trigger a hidden button that causes an asynchronous postback.
OnClientUploadComplete="uploadComplete"
function uploadComplete() {
$get("<%=btnShowUploadResult.ClientID %>").click();
}
<asp:Button ID="btnShowUploadResult" runat="server" CausesValidation="false" Text="hidden" Style="display: none" />
You can store your message in the serverside OnUploadedComplete
into a Session variable and read it in btnShowUploadResult.Click
handler.
这篇关于AsyncFileUpload完成上传后调用服务器端功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!