开发者

issue in updating the page after file upload

I am having a strange issue associated with AsyncFileUpload control. after the upload, I am updating the page by calling__doPostBack function from ClientUploadComplete event handler. it works fine first time, but next ti开发者_如何学JAVAme I try to upload the file, it refreshes the page first before uploading, then does the upload and refreshes the page again. not sure why refresh page is being called twice once before the upload and once after the upload. I have a simplified version of this code which has this bug. any clues please why it is happening?

Markup:

    <form id="form1" runat="server">
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</asp:ToolkitScriptManager>
<div>
    <asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">
        <ContentTemplate>
            <asp:AsyncFileUpload ID="AsyncFileUpload1" runat="server" OnClientUploadComplete="AsyncFileUpload1_ClientUploadComplete"
                OnUploadedComplete="AsyncFileUpload1_UploadedComplete" />                
        </ContentTemplate>
    </asp:UpdatePanel>
</div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
    <ContentTemplate>
        <asp:Button ID="Button1" runat="server" Text="Refresh Data" OnClick="Button1_Click" />
        <asp:Label ID="Label1" runat="server" EnableViewState="false"></asp:Label>
    </ContentTemplate>
</asp:UpdatePanel>
</form>

Javascript:

    <script type="text/javascript">
    function AsyncFileUpload1_ClientUploadComplete() {
        var btnRefreshData = $get("<%=Button1.ClientID%>").name;
        __doPostBack(btnRefreshData, "");
    }

</script>

Code-Behind:

        protected void Button1_Click(object sender, EventArgs e)
    {
        Label1.Text = "Upload complete";
    }

    protected void AsyncFileUpload1_UploadedComplete(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
    {
        System.Threading.Thread.Sleep(3000);
    }


looks like no one can answer this question. I still haven't figured out why this happens, but I put a workaround by adding a flag in session when the upload is complete and check that flag before refreshing the data on the page. this way the data refresh won't happen before the upload. thanks.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜