UpdatePanel不会更新

时间:2012-04-03 18:27:30

标签: asp.net updatepanel

使用AJAX异步文件上传来添加用户图像。我希望在完成异步上传后更新映像。我在后面的代码中使用upImage.Update()来执行此操作,但它似乎没有进行更新。

所有代码都没有错误地运行,并且JS控制台中没有错误。任何帮助,将不胜感激!感谢。

aspx文件:

<h2>That's You 
        <ajax:AsyncFileUpload ID="afuUserImage" runat="server" 
            OnUploadedComplete="uploadComplete"  
            UploadedFileError="uploadError"             
            Width="200px"  
            UploadingBackColor="#b9b9b9" 
            CompleteBackColor="#00FF00"
            ErrorBackColor="#FF0000"
            ThrobberID="theLoader" 
            ClientIDMode="AutoID"  
            CssClass="" />
    </h2>
    <div id="userSettingsImage" runat="server" class="userSettingsImage"> 
        <asp:updatepanel ID="upImage" runat="server" UpdateMode="conditional" ChildrenAsTriggers="false" >
            <ContentTemplate>
                <asp:Image ID="imgUser" runat="server" ImageUrl="~/graphics/blankuser.jpg" />
            </ContentTemplate>
        </asp:updatepanel>       
    </div>

背后的代码......

    protected void uploadComplete(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
    {
        try
        {
            // change photo in space and upload to user photo
            if (afuUserImage.HasFile)
            {

                string strPath = Server.MapPath("~/users/" + this.Context.User.Identity.Name + "/userimages/" + this.Context.User.Identity.Name + ".jpg");
                if (File.Exists(strPath))
                {
                    File.Delete(strPath);
                }
                afuUserImage.SaveAs(strPath);
                imgUser.ImageUrl = imgUser.ImageUrl + "?new" + String.Format("{0:ddMMyyyy}", DateTime.Now);
                upImage.Update();
                Lifeklips_Global.eComms.showMessage("All done!");
            }
            else
            {
                Lifeklips_Global.eComms.showMessage("Oops! This is embarrassing. Your update didn't work, but we're looking into it.  Give it another go.");                    
            }

        }
        catch (Exception ex)
        {
            Lifeklips_Global.errorProcess.logError("Error uploading file: " + ex.Message, "Lifeklips.UserControls.singlephotouploader:uploadComplete");
        }
    }

1 个答案:

答案 0 :(得分:0)

看起来你得错了ImageUrl

imgUser.ImageUrl = imgUser.ImageUrl + "?new" + String.Format("{0:ddMMyyyy}", DateTime.Now);

应该是

imgUser.ImageUrl = "~/users/" + this.Context.User.Identity.Name + "/userimages/" + this.Context.User.Identity.Name + ".jpg?new" + String.Format("{0:ddMMyyyy}", DateTime.Now);