ASP.NET AsyncFileUpload RegisterClientScriptBlock 不起作用
我在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是由当前版本的 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