locked
Enable / Disable a control in ModelPopupExtender with Stream RRS feed

  • Question

  • User1763750567 posted

    Hi

    i am working on a Itextsharp pdf. i have button in my ModelPopUpExtender called "Print". in this button i am creating and printing new pdf document. everything is working fine. i also have two more buttons called "Accept" and "Not Accept", both are disable when page loads. my requirement is when i press Print button, along with the printing of pdf document "Accept" and "Not accept" button get Enable. i tried almost all ways to get it work :(. there is definitely aconflict with pdf document stream. my code is as under.

    <asp:Panel ID="Panel1" runat="server" Style="background-color: #F8FBE9; display: nosne;">
    <table width="500px">
    <tr>
    <td >
    Sales form
    </td>
    </tr>
    <tr>
    <td>
    <table>
    <tr>
    <td>
    <asp:LinkButton ID="btnAccptChk" runat="server" ValidationGroup="grpCCForm" OnClick="btnAccptChk_Click"
    Enabled="false"><img src="../images/AcceptCheck.png" alt="Accept" /></asp:LinkButton>
    </td>
    <td>
    <asp:LinkButton ID="btnNotaccptChk" runat="server" ValidationGroup="grpCCForm" Enabled="false"><img src="../images/NotAcceptCheck.png" alt="Accept"/></asp:LinkButton>
    </td>
    <td>
    <asp:LinkButton ID="btnPrint" runat="server" ValidationGroup="grpCCForm" OnClick="btnPrint_Click" OnClientClick="alert('test');"> <img src="../images/Print.bmp" alt="Print" /></asp:LinkButton>
    </td>
    <td>
    <asp:LinkButton ID="btnExit" runat="server" OnClick="btnExit_Click"> <img src="../images/Exit.bmp" /></asp:LinkButton>
    </td>
    </tr>
    </table>
    </td>
    </tr>
    <tr>
    </asp:Panel>

    <asp:ModalPopupExtender ID="mdlForm" runat="server" TargetControlID="btnopen" BackgroundCssClass="modalBackground"
    PopupControlID="Panel1" CancelControlID="btnClose">
    </asp:ModalPopupExtender>

    in UpdatePanel i have following code.

    <Triggers>
    <asp:PostBackTrigger ControlID="btnPrint" />
    </Triggers>

    on Server side in Print_Click Event follwing code is written.

    var document = new Document(PageSize.LETTER, 0, 0, 0, 0);

    // Create a new PdfWrite object, writing the output to a MemoryStream
    var output = new MemoryStream();
    var writer = PdfWriter.GetInstance(document, output);
    var basefont = BaseFont.CreateFont("c:\\windows\\fonts\\tahoma.ttf", BaseFont.CP1252, BaseFont.NOT_EMBEDDED);

    //Create our paragraph
    Paragraph PrAmount1 = new Paragraph();

    PrAmount1.Add(new Chunk("Test Paragraph", CellFont));
    PrAmount1.Add(Chunk.NEWLINE);
    col.AddText(PrAmount1);
    col.Go();

    writer.CloseStream = false;
    document.Close();
    output.Position = 0;

    Response.ContentType = "application/pdf";
    Response.AddHeader("Content-Disposition", string.Format("attachment;filename=Receipt-{0}.pdf", txtNextCheckNo.Text));
    Response.BinaryWrite(output.ToArray());


    btnAccptChk.Enabled = true;
    btnNotaccptChk.Enabled = true;

    When i try enable code in any other button on the popup it work fine. but with pdf stream it is not. Anybody please help me to solve this problem. Thanks in Advance.

    Sunday, May 11, 2014 7:19 AM

Answers

  • User-417640953 posted

    Hi zahid_kamran,

    Thank you post the issue to asp.net forum.

    According to your description, I see you want to enable the LinkButtons "Accept" and "Not Accept" when click the LinkButton "Print".

    And when you click the "Print" Button, it will cause the page postback and the server side will send a file stream to the client side.

    That's why the page not refresh, if the server send client a file attacment "stream", it will not update page. So the LinkButtons "Accept" and "Not Accept"

    will not becomes enable.

    http://codeverge.com/asp.net.client-side/updating-client-side-while-on-server-side/258823

    For how to do it, I suggest you use the javascript to complete it like below.

     <div>
            <asp:LinkButton ID="LinkButton1" runat="server"  OnClientClick="EnableButtons()" OnClick="LinkButton1_Click">Print</asp:LinkButton>
            <asp:LinkButton ID="LinkButton2" runat="server"  ClientIDMode="Static">Accept</asp:LinkButton>
            <asp:LinkButton ID="LinkButton3" runat="server"  ClientIDMode="Static">NO Accept</asp:LinkButton>
              <script>
                  //disable the linkbuttons on page load 
                      document.getElementById("LinkButton2").disabled = "disabled";
                      document.getElementById("LinkButton3").disabled = "disabled";
                  
                  //enable the linkbuttons on click print Linkbutton
                  function EnableButtons() {
                     
                      document.getElementById("LinkButton2").disabled = "";
                      document.getElementById("LinkButton3").disabled = "";
                  }
        </script>
        </div>

    Hope that helps, thanks.

    Best Regards!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, May 12, 2014 5:08 AM

All replies

  • User-417640953 posted

    Hi zahid_kamran,

    Thank you post the issue to asp.net forum.

    According to your description, I see you want to enable the LinkButtons "Accept" and "Not Accept" when click the LinkButton "Print".

    And when you click the "Print" Button, it will cause the page postback and the server side will send a file stream to the client side.

    That's why the page not refresh, if the server send client a file attacment "stream", it will not update page. So the LinkButtons "Accept" and "Not Accept"

    will not becomes enable.

    http://codeverge.com/asp.net.client-side/updating-client-side-while-on-server-side/258823

    For how to do it, I suggest you use the javascript to complete it like below.

     <div>
            <asp:LinkButton ID="LinkButton1" runat="server"  OnClientClick="EnableButtons()" OnClick="LinkButton1_Click">Print</asp:LinkButton>
            <asp:LinkButton ID="LinkButton2" runat="server"  ClientIDMode="Static">Accept</asp:LinkButton>
            <asp:LinkButton ID="LinkButton3" runat="server"  ClientIDMode="Static">NO Accept</asp:LinkButton>
              <script>
                  //disable the linkbuttons on page load 
                      document.getElementById("LinkButton2").disabled = "disabled";
                      document.getElementById("LinkButton3").disabled = "disabled";
                  
                  //enable the linkbuttons on click print Linkbutton
                  function EnableButtons() {
                     
                      document.getElementById("LinkButton2").disabled = "";
                      document.getElementById("LinkButton3").disabled = "";
                  }
        </script>
        </div>

    Hope that helps, thanks.

    Best Regards!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, May 12, 2014 5:08 AM
  • User1763750567 posted

    Thanks for the reply Fuxiang Zhang.

    Actually my pdf document prints on condition and if it print with true condition then both button should become enable. that is why i can not use javascript approach. 

    For Example

    If (totalamount > 0)

    {

    print pdf

    enable both controls.

    }

    Thnaks.

    Friday, January 23, 2015 2:59 AM