Welcome Guest Search | Active Topics | Sign In | Register

ASPX to PDF UpdatePanel issue Options
Tyler
Posted: Friday, August 9, 2013 10:45:46 AM
Rank: Member
Groups: Member

Joined: 7/11/2013
Posts: 11
Hi,

I have a button which has a client-side function for its OnClientClick property and this function is changed based on whether or not a specific textbox has text in it.

Code: HTML/ASPX
<asp:Button ID="btnNext" runat="server" Font-Bold="true" Text="Next"
        onclick="btnNext_Click" style="text-align: center" Width="80px" />




Code: C#
protected void txtTotal5_TextChanged(object sender, EventArgs e)
        {
            if (txtTotal5.Value.ToString() == "")
            {
                btnNext.OnClientClick = "javascript: return confirm('Please have the employee complete this form.')";
            }
            else
            {
                btnNext.OnClientClick = "";
            }
        }


Because the button needs to be modified, it is inside an UpdatePanel. This works fine if I comment out the code for the ASPX to PDF conversion. My code for the conversion is below:

Code: C#
protected void btnNext_Click(object sender, EventArgs e)
        {

            if (txtTotal5.Value.ToString() == "")
                Panel1.BorderWidth = 5;

            btnNext.Visible = false;
            ASPXToPDF.RenderAsPDF(false);
            ASPXToPDF.AfterRender += new EventHandler(ASPXToPDF_AfterRender);
            Redirect("NextForm.aspx");
            //Response.Redirect("NextForm.aspx");
        }
        
        protected void ASPXToPDF_AfterRender(object sender, EventArgs e)
        {
            HtmlToPdfResult htmlResult = (HtmlToPdfResult)ASPXToPDF.Result;
            htmlResult.PdfDocument.Save("C:\\Form.pdf");
        }

        public string RedirectUrl { get; set; }

        public void Redirect(string url)
        {
            RedirectUrl = url;
            divRedirect.Visible = true;
        }


Code: HTML/ASPX
<div runat="server" id="divRedirect" visible="false">
    <script type="text/javascript">
        if (typeof (eopdf) == "undefined")
            window.location = "<%=RedirectUrl%>";
    </script>
</div>


I use the script in divRedirect because previously I had used Response.Redirect() and had an issue with the next page loading before the PDF finished rendering. My issue now is that if my button is inside the UpdatePanel, I get the following error in the code from "ScriptResource.axd...":

Code: C#
_createPageRequestManagerServerError: function PageRequestManager$_createPageRequestManagerServerError(httpStatusCode, message) {
        var displayMessage = "Sys.WebForms.PageRequestManagerServerErrorException: " +
            (message || String.format(Sys.WebForms.Res.PRM_ServerError, httpStatusCode));
        //Crashes here.
        var e = Error.create(displayMessage, {
            name: 'Sys.WebForms.PageRequestManagerServerErrorException',
            httpStatusCode: httpStatusCode
        });
        e.popStackFrame();
        return e;
    },


If I skip the PDF conversion and just use Response.Redirect() everything works fine with the UpdatePanel and there is no error. Is there some way to avoid this crash but still be able to update my button's OnClientClick property? Possibly a substitute for the UpdatePanel? Any help is appreciated! Thanks in advance!
eo_support
Posted: Friday, August 9, 2013 12:28:31 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,195
Hi,

You can not use UpdatePanel and ASPXToPDF together. UpdatePanel works on the fact that the output is HTML. ASPXToPDF by definition sends PDF file, not HTML file to the client. So they don't go together.

Thanks!
Tyler
Posted: Friday, August 9, 2013 12:41:01 PM
Rank: Member
Groups: Member

Joined: 7/11/2013
Posts: 11
Is there something else I could use instead to update my button? I have UpdatePanels all over most of my pages and they convert fine except when the UpdatePanel is around the button that calls the render which, thankfully, is only on one page.
eo_support
Posted: Friday, August 9, 2013 1:02:07 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,195
Hi,

Have you tried to define your button as a PostBackTrigger?

Thanks!
Tyler
Posted: Friday, August 9, 2013 1:18:18 PM
Rank: Member
Groups: Member

Joined: 7/11/2013
Posts: 11
Well I'm not sure why, but that seems to have fixed it. The button update AND the PDF render both work!

Thank you for your help!
eo_support
Posted: Friday, August 9, 2013 1:29:43 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,195
Hi,

That makes sense. When you use a PostBackTrigger, the button is excluded from making an AJAX call, as such a normal page post back occurs. As long as it's a normal page post back, the PDF will work.

Thanks!


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.