使用 AjaxControlToolkit 中的 AsyncFileUpload 控件上传后更新客户端图像

发布于 2024-09-24 13:41:50 字数 342 浏览 0 评论 0原文

我正在使用 AsyncFileUpload 上传图像,它运行良好,但我想向用户显示他刚刚上传的图像,但我在实现该操作时遇到了麻烦。

我尝试过接收发送者和参数参数的 OnClientUploadComplete 事件,但第二个参数只有文件名(没有相对 url)、长度,但没有保存在服务器上后的文件名。

我还尝试了 ScriptManager.RegisterClientScriptBlock 并调用我自己的函数来传递 url,但由于某种原因我无法使用 jquery 选择 img 控件,似乎代码的和平正在页面的另一个实例中执行...没有把握。

请,如果有人有解决方案或建议,我非常感谢您的回答。

提前致谢。

I am uploading an image with AsyncFileUpload, it works well, but i want to show to the user the image which him just uploaded, but i am having troubles to make that work.

I have tried the OnClientUploadComplete event which receive sender and args paramenters, but the second paramenter only have the file name (without relative url), lenght, but not the file name after saved on the server.

I also tried ScriptManager.RegisterClientScriptBlock and call my own function in order to pass the url, but for some reason i can't select the img control with jquery, seems like that peace of code is executing in another instance of the page... not sure.

Please, if anyone have a solution or suggest, i do appreciate your answer.

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

虫児飞 2024-10-01 13:41:50

将相同的 AsyncFileUpload 控件放在不可见的 div 中
或者
将以下属性添加到页面的标签中:

enctype="multipart/form-data" method="post"

Put the same AsyncFileUpload control within invisible div
or
add the following attributes to the tag of your page:

enctype="multipart/form-data" method="post"
月竹挽风 2024-10-01 13:41:50

该脚本在 iframe 内执行,您应该使用 top.getElementById() 找到该控件

The script executes inside an iframe, you should locate the control using top.getElementById()

脸赞 2024-10-01 13:41:50

当我必须在服务器端上传/保存文件时生成新文件名时,我遇到同样的问题。
我为解决此问题所做的是将新生成的文件名保存到客户端可以访问的服务器端存储中,页面的视图状态不起作用,因此您可以使用带有像 CustomerID 这样的键名的 Session 。

然后从客户端获取生成的文件名,您可以使用回调到同一个Session并获取文件名,然后将其应用到图像控件

    $('image').attr('src','displayimage.aspx?fileName=' + filename);

以获取图像文件流并显示它。
有点棘手,但它有效。

I have the same issue when I have to generate new file name upon uploading /saving file at server side.
What I did to solve this is save the new generated file name into server side storage that client side can access it, viewstate of the page doesn't work, so you might use Session with the key name like CustomerID.

Then get the generated file name from client side, you can use call back to the same Session and get the file name, then apply it to the image control

    $('image').attr('src','displayimage.aspx?fileName=' + filename);

to get the image file stream and display it.
A bit tricky but it works.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文