我在使用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');”在脚本参数中。仍然不起作用。
你们有什么想法?
答案 0 :(得分:1)
这是由当前版本的AsyncFileUpload控件中的错误引起的。基本上它清除内容,写入控件,然后结束请求。这可以防止脚本块呈现。可以在AJAX Control Toolkit bug tracker
上看到更多详细信息和解决方法