在ASP.NET中使用AjaxControlToolkit的异步AJAXFileUpload控件返回数据

编程入门 行业动态 更新时间:2024-10-14 08:24:43
本文介绍了在ASP.NET中使用AjaxControlToolkit的异步AJAXFileUpload控件返回数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用上述控件(请注意,它是ASP.NET。我似乎看到很多人使用用javascript编写的类似名称的控件)来允许使用进度条上载多个文件,拖动-n -drop等。该部分都工作正常,但我需要将两个数据与文件一起返回。具体来说,是用户输入的来自两个文本框的纬度和经度。由于上传控件是异步的,因此文本框的内容不会被回传,因此我无法访问它们。我似乎可以关联一个属性ContextKeys,该属性会将数据发送回服务器,但这是一个静态字段,我不知道如何动态地对其进行操作。我尝试从文本框中挂接ontextchanged事件,并使用这些事件来设置上下文键。回发有效,并且似乎可以设置该值,但是当用户按下上载按钮时,ContextKeys值为空。

I'm using the above control (note it's the ASP.NET one. I seem to see lots of people using a similarly named one written in javascript) to allow upload multiple uploads of files with a progress bar, drag-n-drop, etc. That part all works fine but I need to return two pieces of data along with the file. Specifically, it's a user entered latitude and longitude that comes from two text boxes. Since the upload control is async, the contents of the text boxes don't get posted back so I can't access them. There seems to be a property I can hook into, ContextKeys, which will send the data back to the server, but it's a static field and I don't know how to manipulate it dynamically. I've tried hooking the ontextchanged events from the textboxes and using those to set the context keys. The post back works and it seems to set the value, but when the user presses the upload button the ContextKeys value is empty.

有人可以通过编程方式设置ContextKeys属性吗,或通过上传的方式将数据发送回去的另一种方式?

Does anyone how to programtically set the ContextKeys property, or another way to send data back with the upload?

这是代码:

.ASPX

<div style="float:left; width: 325px;"> <cc1:AjaxFileUpload ID="AjaxFileUpload1" runat="server" Width="325px" onuploadcomplete="UploadComplete" ClientIDMode="Static" /> <cc1:DynamicPopulateExtender ID="AjaxFileUpload1_DynamicPopulateExtender" runat="server" Enabled="True" PopulateTriggerControlID="" TargetControlID="AjaxFileUpload1"> </cc1:DynamicPopulateExtender> </div> <div style="float:left">Latitude: <asp:TextBox ID="tbUploaderLat" runat="server" ontextchanged="tbUploaderLat_TextChanged" AutoPostBack="True"></asp:TextBox><br /> Longitude: <asp:TextBox ID="tbUploaderLon" runat="server" ontextchanged="tbUploaderLon_TextChanged" AutoPostBack="True"></asp:TextBox> </div>

代码隐藏:

protected void UpdateLatLon() //this is called from the two events above { AjaxFileUpload1.ContextKeys = tbUploaderLat.Text + "|" + tbUploaderLon.Text; }

推荐答案

您可以将AjaxFileUpload控件自定义为在此处和此处描述a>并将文本框值传递给UploadCompleted事件处理程序,如下所示:

You can customize AjaxFileUpload control as described here and here and pass textboxes values to UploadCompleted event handler as below:

function uploadStarted(sender, args) { var latitude = $get("<%= tbUploaderLat.ClientID %>").value; var longitude = $get("<%= tbUploaderLon.ClientID %>").value; sender.contextKeys = { "latitude": latitude, "longitude": longitude }; }​

之后,您就可以获取纬度& UploadComplete处理程序中的经度值:

After that, you can get latitude & longitude values in UploadComplete handler:

protected void AjaxFileUpload1_OnUploadComplete(object sender, AjaxFileUploadEventArgs file) { if (!string.IsNullOrEmpty(file.ContextKeys)) { var longLat = new System.Web.Script.Serialization.JavaScriptSerializer().Deserialize<Dictionary<string, string>>(file.ContextKeys); var longitude = longLat["longitude"]; var latitude = longLat["latitude"]; } //code to save file }

更多推荐

在ASP.NET中使用AjaxControlToolkit的异步AJAXFileUpload控件返回数据

本文发布于:2023-11-24 23:49:48,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1627415.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:控件   数据   NET   ASP   AJAXFileUpload

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!