c# - How to download a pdf from a panel in an update panel -


i have site uses master pages.

one of content pages large updatepanel. inside updatepanel regular panel. inside regular panel gridview. inside gridview linkbutton points pdf stored in database.

when click linkbutton retrieve pdf, nothing happens.

i have working on page has no updatepanel.

i have tried firing 'external' button linkbutton , registering button postback event. page posts when click linkbutton pdf not being sent user.

here sample code:

<asp:updatepanel id="updatepanelclaims" runat="server"> <contenttemplate>  <asp:panel id="upclaimattachment" runat="server" visible="false" >          <table id="gridclaimattachmenttable" runat="server" class="table" >             <tr>                 <td >                     <asp:gridview id="grdclaimattachment" runat="server" allowpaging="true" allowsorting="true"                          autogeneratecolumns="false" cssclass="table table-striped table-bordered table-condensed table-hover" emptydatatext="no attachments claim."                         enabletheming="false" onpageindexchanging="grdclaimattachment_pageindexchanging"   pagesize="15" onrowcommand="grdclaimattachment_rowcommand"                         onrowdatabound="grdclaimattachment_rowdatabound" >                         <pagerstyle cssclass="bs-pagination" />                         <alternatingrowstyle cssclass="alternatecolor" />                         <rowstyle cssclass="rowsstyle" />                         <columns>                             <asp:boundfield datafield="id" headertext="id" itemstyle-cssclass="hidecolumn" headerstyle-cssclass="hidecolumn" >                                 <headerstyle horizontalalign="left" />                                 <itemstyle horizontalalign="right" />                             </asp:boundfield>                             <asp:templatefield headertext="file name">                                 <itemtemplate>                                     <asp:linkbutton id="btnviewattachment" text='<%#eval("filename") %>' commandname="viewattachment"                                         commandargument="<%# container.dataitemindex %>" runat="server"></asp:linkbutton></itemtemplate>                             </asp:templatefield>                              <asp:buttonfield buttontype="button" commandname="btndelete" text="delete">                                 <controlstyle cssclass="btn btn-info btn-xs " />                             </asp:buttonfield>                         </columns>                         <selectedrowstyle backcolor="#e2ded6" font-bold="true" forecolor="#333333" />                         <sortedascendingcellstyle backcolor="#e9e7e2" />                         <sortedascendingheaderstyle backcolor="#506c8c" />                         <sorteddescendingcellstyle backcolor="#fffdf8" />                         <sorteddescendingheaderstyle backcolor="#6f8dae" />                     </asp:gridview>                 </td>             </tr>             <tr >                 <td>                     <div class="container">                         <div class="form-group form-group-sm form-groupnospace">                             <div class="row">                                 <div class=" col-xs-4 col-xs-offset-4 text-right">                                     <asp:button id="btnclaimattachmentadd" runat="server" cssclass="btn btn-primary btn-sm btn-block" text="add attachment" onclick="btnclaimattachmentadd_click"/>                                 </div>                             </div>                         </div>                         </div>                  </td>             </tr>         </table>  </asp:panel> <%-- attachment update panel --%>  <asp:button id="btnclickme" runat="server" onclick="btnclickme_click" visible="false" />  </contenttemplate>   <triggers>       <asp:postbacktrigger controlid="btnclickme" />   </triggers> </asp:updatepanel> <%-- updatepanelclaims --%> 

in code behind have this:

    protected void btnclickme_click(object sender, eventargs e, claimattachment objattachment)     {         viewattachment(objattachment);     }      private void viewattachment(claimattachment objattachment)     {         response.clear();         response.buffer = true;         response.contenttype = "application/pdf";         response.appendheader("content-disposition", "attachment;filename=" + objattachment.filename);         response.charset = "";         response.cache.setcacheability(httpcacheability.nocache);         response.binarywrite(objattachment.attachment);         response.flush();         response.end();     } 

update: forgot critical code!

    protected void grdclaimattachment_rowcommand(object sender, gridviewcommandeventargs e)     {         try         {             int index = convert.toint32(e.commandargument);              if (index >= grdclaimattachment.rows.count)                 return;              int idkey = convert.toint32(grdclaimattachment.rows[index].cells[0].text);             claimattachment objclaimattachment = claimattachment.retrievebyid((string)session["username"], idkey);              if (e.commandname == "btndelete")             {                 ltldeleteid.text = idkey.tostring();                 ltlrecordtype.text = "attachment";                 confirmdialog(string.format("delete attachment: {0} ?", objclaimattachment.filename));             }             else if (e.commandname == "viewattachment")             {                 //btnclickme.commandargument = idkey.tostring();                 //btnclickme_click(sender, e);                 btnclickme.click += new eventhandler((s1, e1) => btnclickme_click(s1, e1, objclaimattachment));                 btnclickme_click(sender, e, objclaimattachment);             }         }         catch (blexception be)         {             errdialog(be.message);         }     } 

the linkbutton in grid calling click event of external button perform pdf download...

what missing?? said, works if remove updatepanels need them other things...

thx!

the postbacktrigger class key solution, can used trigger full page reload required download reponse work. downloads not work partial postback.

however, buttons should trigger postback inside grid, using single postbacktrigger in page markup not enough, you need specific trigger each button / row.

use (call page_load)

private void registerpostbackcontrols() {     foreach (gridviewrow row in grdclaimattachment.rows)     {         linkbutton button = row.findcontrol("btnviewattachment") linkbutton;         scriptmanager.getcurrent(this).registerpostbackcontrol(button);     }  } 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -