参数传递给服务器端与asyncfileupload

参数传递给服务器端与asyncfileupload

本文介绍了参数传递给服务器端与asyncfileupload(ajaxcontroltoolkit)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用ASP.NET和我需要一个简单的方法来上传文件异步。所以我试图用asyncfileupload(阿贾克斯控制工具包),但我还需要将参数传递到服务器端。我该怎么办呢?谢谢。

下面是我的code:

在客户端:

 < ASP:ToolkitScriptManager ID =ToolkitScriptManager1=服务器>
< / ASP:ToolkitScriptManager>
 < ASP:AsyncFileUpload ID =afuMedia=服务器UploaderStyle =现代OnUploadedComplete =afuMedia_UploadedComplete/>

在服务器端:

 保护无效afuMedia_UploadedComplete(对象发件人,AsyncFileUploadEventArgs E)
  {
      // INT ID = int.Parse(的Request.QueryString [身份证]);
      字符串mediaPath = ConfigurationParameters.MediaPath;
      字符串文件路径= CurrentBrand.Brand code +\\\\+ CurrentCulture.Culture code +\\\\+highlights-+ ID;
      字符串physicalPath = Path.Combine(的MapPath(〜/+ mediaPath),文件路径);      afuMedia.SaveAs(physicalPath);
  }


解决方案

添加客户端处理程序通过 OnClientUploadStarted 属性上传开始和如下使用它:

 < ASP:AsyncFileUpload ID =afuMedia=服务器UploaderStyle =现代
    OnUploadedComplete =afuMedia_UploadedComplete
    OnClientUploadStarted =afuMedia_OnClientUploadStarted/>功能afuMedia_OnClientUploadStarted(发件人,参数){
    VAR ID = 123;
    VAR URL = sender.get_postBackUrl();
    网址+ = url.indexOf(?)=== -1? ? :与&;
    URL + =(ID =+ id.toString());
    sender.set_postBackUrl(URL);
}

有了这个code所有你需要做你自己是提供价值正确的ID;

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.

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);
  }
解决方案

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

<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;

这篇关于参数传递给服务器端与asyncfileupload(ajaxcontroltoolkit)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 09:00