asp.net - AJAX updatepanel giving error -
i trying use ajax updateprogress display loading image when zip file being created following error:
microsoft jscript runtime error: sys.webforms.pagerequestmanagerparsererrorexception: message received server not parsed. common causes error when response modified calls response.write(), response filters, httpmodules, or server trace enabled. detals: error parsing near 'pk'.
below code .aspx page
<html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <style type="text/css"> #progressbackgroundfilter { position: fixed; top: 0px; bottom: 0px; left: 0px; right: 0px; overflow: hidden; padding: 0; margin: 0; background-color: #000; filter: alpha(opacity=50); opacity: 0.5; z-index: 1000; } #processmessage { position: fixed; top: 30%; left: 43%; padding: 10px; width: 14%; z-index: 1001; background-color: #fff; border: solid 1px #000; } </style> </head> <body> <form id="form1" runat="server"> <div> <asp:scriptmanager id="scriptmanager1" runat="server"> </asp:scriptmanager> <asp:updatepanel id="updatepanel1" runat="server"> <contenttemplate> <asp:checkbox id="chb_pass" runat="server" text="do want zip file have password?" autopostback="true" /> <br /> <asp:textbox id="txt_password" runat="server" maxlength="20" visible="false" style="margin-top: 6px" width="152px"></asp:textbox> <asp:requiredfieldvalidator id="requiredfieldvalidator1" runat="server" controltovalidate="txt_password" errormessage="* need password!"></asp:requiredfieldvalidator> <br /> <asp:button id="btndownloadphotos" runat="server" text="download album photos" height="27px" style="margin-top: 3px" width="284px" /> </contenttemplate> <triggers> <asp:asyncpostbacktrigger controlid="btndownloadphotos" eventname="click" /> </triggers> </asp:updatepanel> <asp:updateprogress id="updateprogress1" runat="server" associatedupdatepanelid="updatepanel1"> <progresstemplate> <div id="progressbackgroundfilter"> </div> <div id="processmessage"> preparing download...<br /> <br /> <img alt="loading" src="img/ajax-loader.gif" /> </div> </progresstemplate> </asp:updateprogress> </div> </form> </body> </html>
...and below code aspx.vb page
imports system.io imports system.text imports ionic.zip partial class download inherits system.web.ui.page protected sub button1_click(byval sender object, byval e system.eventargs) handles btndownloadphotos.click dim photofilelist new list(of string) dim uploaddirectory string = server.mappath("") & "\uploads\" dim albumname string = "cricket" photofilelist.add(uploaddirectory & "cimg1455.jpg") photofilelist.add(uploaddirectory & "cimg1453.jpg") photofilelist.add(uploaddirectory & "cimg1451.jpg") photofilelist.add(uploaddirectory & "cimg1450.jpg") createzip(photofilelist, albumname) end sub private sub createzip(byval listoffilename list(of string), byval albumname string) ' tell browser we're sending zip file! dim downloadfilename string = string.format(albumname & "-{0}.zip", datetime.now.tostring("yyyy-mm-dd-hh_mm_ss")) response.contenttype = "application/zip" response.addheader("content-disposition", "filename=" & downloadfilename) ' zip contents of selected files using zip new zipfile() 'add password protection, if specified if chb_pass.checked = true zip.password = txt_password.text 'this encryption weak! please see http://cheeso.members.winisp.net/dotnetziphelp/html/24077057-63cb-ac7e-6be5-697fe9ce37d6.htm more details zip.encryption = encryptionalgorithm.pkzipweak end if ' construct contents of readme.txt file included in zip dim readmemessage string = string.format("this zip file {0} contains following photos within " & albumname & " album:{1}{1}", downloadfilename, environment.newline) ' add checked files zip each li string in listoffilename.toarray() ' record file included in readmemessage readmemessage &= string.concat(vbtab, "* ", li.tostring, environment.newline) ' add file zip (use value of "" second parameter put files in "root" folder) zip.addfile(li.tostring, "your files") next ' add readme.txt file zip zip.addentry("readme.txt", readmemessage, encoding.ascii) ' send contents of zip output stream zip.save(response.outputstream) end using end sub protected sub chb_pass_checkedchanged(byval sender object, byval e system.eventargs) handles chb_pass.checkedchanged if chb_pass.checked = true txt_password.visible = true elseif chb_pass.checked = false txt_password.visible = false end if end sub end class
any ideas how can solve problem? appreciated.
thanks
i had similar problem in past trying stream excel document button inside update panel. here solution, hope helps.
vb.net:
protected sub page_load(byval sender object, byval e system.eventargs) handles me.load dim sm = scriptmanager.getcurrent(me.page) sm.registerpostbackcontrol(me.your_button) addpostbacktrigger(me.your_button.uniqueid.tostring()) end sub public sub addpostbacktrigger(byval controlid string) dim existingtrigger = findpostbacktrigger(controlid) if existingtrigger nothing dim trigger new postbacktrigger() trigger.controlid = controlid me.your_update_panel_goes_here.triggers.add(trigger) end if end sub public sub removepostbacktrigger(byval controlid string) dim existingtrigger = findpostbacktrigger(controlid) if existingtrigger isnot nothing me.your_update_panel_goes_here.triggers.remove(existingtrigger) end if end sub private function findpostbacktrigger(byval controlid string) postbacktrigger each trigger in me.your_update_panel_goes_here.triggers if trigger.gettype().name = "postbacktrigger" dim pt = ctype(trigger, postbacktrigger) if pt.controlid = controlid return pt end if end if next return nothing end function
c#:
protected void page_load(object sender, eventargs e) { scriptmanager sm = scriptmanager.getcurrent(page); if (sm != null) sm.registerpostbackcontrol(your_control); addpostbacktrigger(your_control.uniqueid); } private void addpostbacktrigger(string controlid) { postbacktrigger existingtrigger = findpostbacktrigger(controlid); if (existingtrigger != null) { var trigger = new postbacktrigger {controlid = controlid}; your_update_panel.triggers.add(trigger); } } private postbacktrigger findpostbacktrigger(string controlid) { return your_update_panel .triggers.oftype<postbacktrigger>() .firstordefault(pt => pt.controlid == controlid); }
Comments
Post a Comment