javascript - HttpContext.Current.Response.End() skip the execution -
i exporting gridview
excel sheet through javascript
using webmethod
. since rows in gridview
contains template controls label,anchor,etc
., created @ runtime through javascript
not @ design, use pass rows array web method. export have created table , map array returned javascript
function. problem while debugging, execution skipped on httpcontext.current.response.end
, couldn't export grid. don't know why happening. below code of web method
<webmethod(enablesession:=true, transactionoption:=enterpriseservices.transactionoption.requiresnew)> _ <scriptmethod(responseformat:=responseformat.xml, usehttpget:=true)> _ public shared sub xlexport(byval filename string, byval row object()()) httpcontext.current.response.clear() httpcontext.current.response.addheader("content-disposition", string.format("attachment; filename={0}", filename)) httpcontext.current.response.contenttype = "application/vnd.ms-excel" dim sw stringwriter = new stringwriter dim htw htmltextwriter = new htmltextwriter(sw) dim table table = new table table.gridlines = gridlines.both integer = 0 row.length - 1 dim dr new tablerow j integer = 0 row(i).length - 1 dim dc new tablecell dim lt new literalcontrol lt.text = row(i)(j) dc.controls.add(lt) dr.cells.add(dc) next table.rows.add(dr) next table.rendercontrol(htw) httpcontext.current.response.write(sw.tostring) httpcontext.current.response.end() end sub
i tried in own. stored rows in hidden field. , on server side converted them array table. use above code normal function not webmethod
sub download_click() dim str_arr object() dim str_arr1 object() str_arr = hdn_gvcheck.value.split(",") str_arr1 = hdn_headerdiv.value.split(",") dim len integer = (str_arr.length - 2) / 36 dim twodarr object()() = new object(len - 1)() {} len = (str_arr1.length - 2) / 36 dim headarr object()() = new object(len - 1)() {} dim ind integer = 0 dim start integer = 1 dim fnsh integer = 36 headarr(ind) = new object(35) {} l1: twodarr(ind) = new object(35) {} dim col integer = 0 integer = start fnsh twodarr(ind)(col) = str_arr(i) if ind = 0 headarr(ind)(col) = str_arr1(i) end if col += 1 next if ind < 7 ind += 1 start = fnsh + 1 fnsh = start + 35 goto l1 end if doexport("position.xls", twodarr, headarr, gvcheck) end sub sub doexport(byval filename string, byval row object()(), byval head object()(), byval gv gridview) httpcontext.current.response.clear() httpcontext.current.response.buffer = true httpcontext.current.response.addheader("content-disposition", string.format("attachment; filename={0}", filename)) httpcontext.current.response.contenttype = "application/vnd.ms-excel" httpcontext.current.response.charset = "" dim table table = new table table.gridlines = gv.gridlines 'gridlines.both 'for integer = 0 head.length - 1 dim hdr new tablerow j integer = 0 head(0).length - 1 dim dc new tablecell dc.style("font-weight") = "bold" dim lt new literalcontrol(head(0)(j)) 'lt.text = row(i)(j) dc.controls.add(lt) hdr.cells.add(dc) next table.rows.add(hdr) 'next integer = 0 row.length - 1 dim dr new tablerow j integer = 0 row(i).length - 1 dim dc new tablecell dim lt new literalcontrol(row(i)(j)) 'lt.text = row(i)(j) dc.controls.add(lt) dr.cells.add(dc) next table.rows.add(dr) next dim sw stringwriter = new stringwriter dim htw htmltextwriter = new htmltextwriter(sw) table.rendercontrol(htw) httpcontext.current.response.write(sw.tostring) 'sw.tostring httpcontext.current.response.end() end sub
Comments
Post a Comment