asyncfileupload 完成后 ajaxcontroltoolkit 设置隐藏值
我有一个 asyncfileupload 控件,正在使用 ajaxcontroltoolkit 中的控件。在后面的代码中完成的文件上,我处理该文件并将文件中的信息写入数据库。我从数据库中获取记录的 id,需要将其写入 asp 隐藏字段。我尝试过设置值:
fldImageID.Value = pimg.IdImageGroup.ToString();
我尝试过注册一个脚本,就像我在 网站上的示例:
ScriptManager.RegisterClientScriptBlock(
ImageFileUploader,
ImageFileUploader.GetType(),
"script1",
"alert('hi'); top.document.getElementById('"
+ fldImageID.ClientID
+ "').value='"
+ pimg.IdImageGroup.ToString()
+ "'; top.document.getElementById('"
+ lblError.ClientID
+ "').innerHTML = 'image uploaded'",
true);
我刚刚尝试在响应中嵌入 javascript。从我设置的方法写入调用来处理上传的内容文件。到目前为止我所做的一切都没有效果。完成所有操作后,隐藏字段仍然不包含所需的值。
I have an asyncfileupload control that I'm using from the ajaxcontroltoolkit. On the file complete in the code behind I process the file and write the information in the file to a database. I get the id of the record from the database, and this needs to be written to an asp hidden field. I've tried just setting the value:
fldImageID.Value = pimg.IdImageGroup.ToString();
I've tried Registering a script like I've seen in an example on a website:
ScriptManager.RegisterClientScriptBlock(
ImageFileUploader,
ImageFileUploader.GetType(),
"script1",
"alert('hi'); top.document.getElementById('"
+ fldImageID.ClientID
+ "').value='"
+ pimg.IdImageGroup.ToString()
+ "'; top.document.getElementById('"
+ lblError.ClientID
+ "').innerHTML = 'image uploaded'",
true);
I've just tried embedding javascript in a response.Write call from the method I've set to process the uploaded file. Nothing I've done has worked so far. After I've done everything the hidden field still does not contain the required value.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
更好、更简单的解决方案是在代码后面:
在我的例子中,safeFilename 是唯一的文件名,在处理重复的文件名后,即第五次上传的sample.png 中的sample_5.png。
请参阅http://forums.asp.net/t/1503989.aspx
The better and more simple solution is in code behind:
In my case, safeFilename is the unique filename, after handling duplicate filename, i.e. sample_5.png in the 5th upload of sample.png.
See http://forums.asp.net/t/1503989.aspx
当我从事这个工作时,我找到了一个可以接受的解决方案。从那时起,我收到了有同样问题的人发来的电子邮件,并询问我是否找到了解决方案。所以我在这里展示它,删除任何无关的代码:
从具有 FileUpload 控件的用户控件中,我首先在 FileUploadComplete 处理程序的背面设置会话变量:
*在 ascx 文件 (upload_chart.ascx )我有AsyncFileUpload,重要的是OnUploadComplete和OnClientUploadComplete:*
*在ascx文件(upload_chart.ascx.cs)后面的代码中我处理FileUploadComplete:*
Javascript 和脚本方法用于设置页面上的值,这是我的脚本方法的代码隐藏:
这里是 javascript:
// 在 aspx 前端 (chartofthedayadmin.aspx) 我有 javascript
// 调用 Web 方法和 javascript 失败消息:
*// 用户控件 (upload_chart.ascx) 上的 javascript 设置隐藏字段的值*
注意:确保您的脚本管理器具有 EnablePageMethods="true"。
I found an acceptable solution back when I was working on this. And since then I've received emails from people who have had the same problem and have been asking if I found a solution. So I'm presenting it here, stripping out any extraineous code:
From the user control that has the FileUpload control I first set the session variable on the back side in the FileUploadComplete handler:
*in the ascx file (upload_chart.ascx) I have the AsyncFileUpload, what is important is the OnUploadComplete and the OnClientUploadComplete:*
*in the code behind of the ascx file (upload_chart.ascx.cs) I handle the FileUploadComplete:*
Javascript and script methods are used to set the value on the page, here is my codebehind for the script method:
Here is the javascript:
// on the aspx front end (chartofthedayadmin.aspx) I have the javascript
// to call the Web method and the javascript failed message:
*// javascript on the user control (upload_chart.ascx) to set the value of the hidden field*
note: Make sure your scriptmanager has EnablePageMethods="true".
使用
jQuery
这非常容易。在您的页面中放置一个 html 隐藏输入控件,而不是asp:hidden
输入控件。添加一个类,例如"hiddenPhoto"
到您的 html 隐藏控件。所以可以说我们的控件 html 是这样的
现在使用
OnClientUploadComplete
js 方法中的类选择器访问它并设置其值。声明runat="server"
以便在服务器端访问它的值。问候
This is pretty easy with
jQuery
. Have an html hidden input control placed in your page, not theasp:hidden
input control. Add a class lets say"hiddenPhoto"
to your html hidden control.so lets say our control html is like this
Now access it using class selector in your
OnClientUploadComplete
js method and set its value. Have it declaredrunat="server"
in order to access its value on the server side.Regards