c# - Binding grid after generating pdf and creating download -


i have page grid generates pdf files using itextsharp dll. code following:

  var document = new document();                             bool download = true;                             if (download == true)                             {                                 pdfwriter.getinstance(document, response.outputstream);                                 bindgrid();                             }                             string filename = "pdf" + datetime.now.ticks + ".pdf";                             try                             {                                  document.open();                                 // adding contents pdf file....                             }                             catch (exception ex)                             {                                 lblmessage.text = ex.tostring();                             }                                                         {                                 document.close();                                 bindgrid();                             }                             response.contenttype = "application/pdf";                             response.addheader("content-disposition", "attachment; filename=" + filename);                             response.flush();                             response.end();                             bindgrid();                         } 

i need bind grid once download window pops up, or after user clicks download doesn't matters, need grid bind after user generates pdf file. have tried binding grid on numerous places can see, none of them worked, grid binds after refresh page :(.

is there way can ???

response.end ends page life cycle.

i suggest to:

  1. generate pdf file , save on server
  2. bind grid
  3. flush generated file

something this:

    protected void page_load(object sender, eventargs e)     {         if (!page.ispostback)             bindgrid(); // bind grid here          // after reloading page flush file         if (session["file"] != null)             flushfile();     }      protected void gv_rowcommand(object sender, gridviewcommandeventargs e)     {         // generate & save pdf here          session["file"] = fullfilepath; // full path of file saved.          response.redirect(request.rawurl); // reload page     }      private void flushfile()     {         string fullfilepath = session["file"].tostring();         session["file"] = null;           // flush file here     } 

hope helps.

cheers


Comments

Popular posts from this blog

c++ - OpenMP unpredictable overhead -

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

javascript - Wordpress slider, not displayed 100% width -