gpt4 book ai didi

c# - asyncfileupload 上传后显示图像而不刷新页面

转载 作者:行者123 更新时间:2023-11-30 13:41:42 26 4
gpt4 key购买 nike

我一直在努力解决这个问题,但没有运气。

使用 asyncfileupload 控件上传文件并显示图像。上传工作正常,如果我重新加载/刷新页面,则会显示图像。

但需要知道如何在不重新加载/刷新页面的情况下执行此操作。

阅读在线帖子后,我看到了使用 scriptmanager 的建议,但这对我不起作用:

    protected void FileUploadComplete(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
{

.
.
.
.

ScriptManager.RegisterStartupScript(this, GetType(), "TestAlert",
"window.parent.document.getElementById('" + img_ProfilePic.ClientID + "').src='" + "http://www.site.com/default.jpg" + "');",
true);

谢谢,贝鲁兹

最佳答案

在发现 user554134 提到的错误之前浪费了几个小时,我想出了以下使用 jQuery 的解决方案(以及 asyncfileupload 控件)。

  • 首先得到编译好的版本修复了错误的 AjaxToolkit,每个 user554134 的链接。

  • 添加一些 jQuery 来隐藏/显示图像。

$(document).ready(function () {
$("#imgConfirmation").hide();
});

要记住的关键点是 AsyncFileUpload 控件使用 iframe,因此在调用“显示”函数时需要让 jquery 访问框架的父级。例如:

        function showImage(imagePath) {
$('#imgConfirmation', window.parent.document).attr("src", imagePath);
$('#imgConfirmation', window.parent.document).show();
}
  • 在您的 UploadedComplete 事件中,保存文件后,注册挂接到 js 函数的客户端脚本。例如,
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "showImage", "showImage('" + myLink + "');", true);

关于c# - asyncfileupload 上传后显示图像而不刷新页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4721114/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com