ASP.NET AsyncFileUpload RegisterClientScriptBlock 不起作用

发布于 2024-09-17 06:34:32 字数 1596 浏览 4 评论 0原文

我在使用 ScriptManager 的 RegisterClientScriptBlock 时遇到问题,该块不起作用。

我有一个 AsyncFileUpload,我想在上传后动态预览上传的图像。

UploadedComplete 连接到 Page_Init 中,这是服务器端的 UloadedComplete 块代码

void fileUpload_UploadedComplete(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
{
    string csb = string.Empty; 
    string tempfolder = "picserver/posts/temp/" + Session["Username"] + "_" + DateTime.Today.ToString("yyyy_MM_d") + ".jpg";
    string newfile = Server.MapPath(tempfolder);

    fileUpload.SaveAs(newfile);

    Byte[] f = File.ReadAllBytes(newfile);
    Imaging i = new Imaging();
    i.ResizeImageFile(newfile, newfile, 64);

    csb = "$(\"" + postImagePreview.ClientID + "\").innerHTML = '<img src=\"" + tempfolder + "\" alt=\"\" />'";
    System.Diagnostics.Debug.WriteLine("CSB: " + csb);
    ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "preview", csb, true);
}

,这是 html,

<asp:Label ID="postImagePreview" runat="server" />
Upload a preview of your advertisement.
<asp:AsyncFileUpload ID="fileUpload" runat="server" UploaderStyle="Traditional" UploadingBackColor="#CCFFFF" ThrobberID="myThrobber" /> <asp:Label runat="server" ID="myThrobber" style="display:none;" ></asp:Label>

这是我的 ScriptBlock

csb = "$(\"" + postImagePreview.ClientID + "\").innerHTML = '<img src=\"" + tempfolder + "\" alt=\"\" />'";
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "preview", csb, true);

,它不起作用..即使我输入“alert('hello');”在脚本参数中。还是不行。

你们知道为什么吗?

I have a problem working with ScriptManager's RegisterClientScriptBlock which is not working.

I have a AsyncFileUpload and I want to preview the uploaded image dynamically after the upload.

the UploadedComplete is wired in Page_Init and here's the UloadedComplete block code in server side

void fileUpload_UploadedComplete(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
{
    string csb = string.Empty; 
    string tempfolder = "picserver/posts/temp/" + Session["Username"] + "_" + DateTime.Today.ToString("yyyy_MM_d") + ".jpg";
    string newfile = Server.MapPath(tempfolder);

    fileUpload.SaveAs(newfile);

    Byte[] f = File.ReadAllBytes(newfile);
    Imaging i = new Imaging();
    i.ResizeImageFile(newfile, newfile, 64);

    csb = "$(\"" + postImagePreview.ClientID + "\").innerHTML = '<img src=\"" + tempfolder + "\" alt=\"\" />'";
    System.Diagnostics.Debug.WriteLine("CSB: " + csb);
    ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "preview", csb, true);
}

and here's the html

<asp:Label ID="postImagePreview" runat="server" />
Upload a preview of your advertisement.
<asp:AsyncFileUpload ID="fileUpload" runat="server" UploaderStyle="Traditional" UploadingBackColor="#CCFFFF" ThrobberID="myThrobber" /> <asp:Label runat="server" ID="myThrobber" style="display:none;" ></asp:Label>

here's my ScriptBlock

csb = "$(\"" + postImagePreview.ClientID + "\").innerHTML = '<img src=\"" + tempfolder + "\" alt=\"\" />'";
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "preview", csb, true);

and it's not working.. even if I put "alert('hello');" in script parameter. still doesn't work.

you guys have any idea why?

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

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

发布评论

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

评论(1

愿得七秒忆 2024-09-24 06:34:33

这是由当前版本的 AsyncFileUpload 控件中的错误引起的。本质上,它清除内容,写入控件,然后结束请求。这会阻止脚本块渲染。更多详细信息和解决方法可以在 AJAX Control Toolkit bug tracker 上查看

This is caused by a bug in the current version of the AsyncFileUpload control. Essentially it clears the content, writes the control, and then ends the request. This prevents the script block from rendering. More details and a workaround can be seen on the AJAX Control Toolkit bug tracker

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