Ajax AsyncFileUpload触发服务器代码但不更新客户端

时间:2022-02-09 18:49:45

I have an asyncfileupload control inside an update panel.

我在更新面板中有一个asyncfileupload控件。

In UploadedComplete, i save file to server.

在UploadedComplete中,我将文件保存到服务器。

 protected void ImageFileUpload_UploadedComplete(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
{
    System.Threading.Thread.Sleep(5000);
        if (ImageFileUpload.HasFile)
        {
            Extension= System.IO.Path.GetExtension(ImageFileUpload.FileName);

            TempImageUpload(ImageFileUpload.FileName.ToString(), Extension.Value);
            FileImage.ImageUrl = "~/Temp/" + Session["ID"].ToString() + Extension.Value;
            RemoveImageButton.Visible = true;
        }
}

The file succesfully upload and fires the correct server side code.

该文件成功上载并触发正确的服务器端代码。

But don't update viewstate and controls.

但是不要更新viewstate和控件。

 private string Extension
{
    get { 
        if(ViewState["Extension"]==null)
            return string.Empty;
        else
       return (string)ViewState["Extension"]; }
    set { ViewState["Extension"] = value; }
}

1 个解决方案

#1


1  

I save file On UploadedComplete event.

我保存文件On UploadedComplete事件。

  protected void ImageFileUpload_UploadedComplete(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
  {
    if (ImageFileUpload.HasFile)
    {
      ImageFileUpload.SaveAs(Request.PhysicalApplicationPath + "Temp\\" + Session["ID"].ToString() + extension);
    }
  }

and fot change control in client side, i use OnClientUploadComplete.

并且在客户端更改控件,我使用OnClientUploadComplete。

function uploadComplete(sender, args) {
        var filename = args.get_fileName();
        document.getElementById('<%= Extension.ClientID  %>').value = "." + filename.split('.').pop();
        var btn = document.getElementById('<%= RemoveImageButton.ClientID  %>')
        btn.style.visibility = 'visible';
    }

#1


1  

I save file On UploadedComplete event.

我保存文件On UploadedComplete事件。

  protected void ImageFileUpload_UploadedComplete(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
  {
    if (ImageFileUpload.HasFile)
    {
      ImageFileUpload.SaveAs(Request.PhysicalApplicationPath + "Temp\\" + Session["ID"].ToString() + extension);
    }
  }

and fot change control in client side, i use OnClientUploadComplete.

并且在客户端更改控件,我使用OnClientUploadComplete。

function uploadComplete(sender, args) {
        var filename = args.get_fileName();
        document.getElementById('<%= Extension.ClientID  %>').value = "." + filename.split('.').pop();
        var btn = document.getElementById('<%= RemoveImageButton.ClientID  %>')
        btn.style.visibility = 'visible';
    }