使用asyncfileupload(ajaxcontroltoolkit)将参数传递到服务器端

时间:2022-03-26 15:04:08

I use ASP.NET and i need an easy way to upload a file asynchronously. So I tried to use asyncfileupload (Ajax control toolkit) but I also need to pass parameters to the server side. How can I do that ? thanks.

我使用ASP.NET,我需要一种简单的方法来异步上传文件。所以我尝试使用asyncfileupload(Ajax控件工具包),但我还需要将参数传递给服务器端。我怎样才能做到这一点 ?谢谢。

Here is my code :

这是我的代码:

on client side :

在客户端:

<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</asp:ToolkitScriptManager>
 <asp:AsyncFileUpload ID="afuMedia" runat="server" UploaderStyle="Modern" OnUploadedComplete="afuMedia_UploadedComplete" />

on server side :

在服务器端:

  protected void afuMedia_UploadedComplete(object sender, AsyncFileUploadEventArgs e)
  {
      //int id = int.Parse(Request.QueryString["id"]);
      string mediaPath = ConfigurationParameters.MediaPath;
      string filePath = CurrentBrand.BrandCode + "\\" + CurrentCulture.CultureCode + "\\" + "highlights-" + id;
      string physicalPath = Path.Combine(MapPath("~/" + mediaPath), filePath);

      afuMedia.SaveAs(physicalPath);
  }

1 个解决方案

#1


2  

Add client handler for upload start via the OnClientUploadStarted property and use it as below:

通过OnClientUploadStarted属性添加上传启动的客户端处理程序,并使用它如下所示:

<asp:AsyncFileUpload ID="afuMedia" runat="server" UploaderStyle="Modern"
    OnUploadedComplete="afuMedia_UploadedComplete" 
    OnClientUploadStarted="afuMedia_OnClientUploadStarted" />

function afuMedia_OnClientUploadStarted(sender, args){
    var id = 123;
    var url = sender.get_postBackUrl();
    url += url.indexOf("?") === -1 ? "?" : "&";
    url += ("id=" + id.toString());
    sender.set_postBackUrl(url);
}

With this code all that you need to do on you own it's to provide correct id value;

使用此代码,您需要做的就是提供正确的id值;

#1


2  

Add client handler for upload start via the OnClientUploadStarted property and use it as below:

通过OnClientUploadStarted属性添加上传启动的客户端处理程序,并使用它如下所示:

<asp:AsyncFileUpload ID="afuMedia" runat="server" UploaderStyle="Modern"
    OnUploadedComplete="afuMedia_UploadedComplete" 
    OnClientUploadStarted="afuMedia_OnClientUploadStarted" />

function afuMedia_OnClientUploadStarted(sender, args){
    var id = 123;
    var url = sender.get_postBackUrl();
    url += url.indexOf("?") === -1 ? "?" : "&";
    url += ("id=" + id.toString());
    sender.set_postBackUrl(url);
}

With this code all that you need to do on you own it's to provide correct id value;

使用此代码,您需要做的就是提供正确的id值;