Welcome Guest Search | Active Topics | Sign In | Register

ArgumentNullException using RenderAsPDF prior to Response.Redirect() Options
Tyler
Posted: Thursday, July 11, 2013 5:23:58 PM
Rank: Member
Groups: Member

Joined: 7/11/2013
Posts: 11
I am getting the following Exception when I call ASPXToPDF.RenderAsPDF(false) followed by Response.Redirect("AnotherForm.aspx"):

Server Error in '/' Application.


Value cannot be null.
Parameter name: type
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentNullException: Value cannot be null.
Parameter name: type

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:


[ArgumentNullException: Value cannot be null.
Parameter name: type]
System.Activator.CreateInstance(Type type, Boolean nonPublic) +7469126
System.Activator.CreateInstance(Type type) +6
EO.Web.Internal.dg.a() +28
EO.Web.ASPXToPDF.a(String A_0, Stream A_1) +74
EO.Web.Internal.ms.a(b[] A_0) +109
EO.Web.Internal.a.Close() +61
System.Web.HttpWriter.Filter(Boolean finalFiltering) +69
System.Web.HttpResponse.FilterOutput() +82
System.Web.ApplicationStepManager.ResumeSteps(Exception error) +501
System.Web.HttpApplication.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData) +123
System.Web.HttpRuntime.ProcessRequestInternal(HttpWorkerRequest wr) +379

Code: C#
C# Code:

        protected void submit_Click(object sender, EventArgs e)
        {
            ASPXToPDF.RenderAsPDF(false);
            Response.Redirect("AnotherForm.aspx");
        }


Please help me determine the cause of this exception. Thanks in advance!
eo_support
Posted: Thursday, July 11, 2013 6:01:07 PM
Rank: Administration
Groups: Administration

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

ASPXToPDF relies on a "normal" page cycle so that it can capture the entire page output HTML. When you call Response.Redirect, it interrupt the page rendering process so ASPXToPDF can't no longer get the output HTML thus causing problems.

To use ASPXToPDF and Redirect the same time, you can put something like this in your .ASPX page:

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


And the following code in your code behind:

Code: C#
public string RedirectUrl { get; set; }

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


Now you can call Redirect("AnotherForm.aspx") from your code to redirect to another page. The code sets property RedirectUrl, and then renders a small piece of JavaScript to redirect to RedirectUrl by setting window.location. This way the whole page is still rendered. However the redirection does not occur inside the converter because the script checks typeof(eopdf). Variable "eopdf" is only defined when the page is running inside the converter.

Hope this helps. Please feel free to let us know if you have any more questions.

Thanks!
Tyler
Posted: Friday, July 12, 2013 9:10:44 AM
Rank: Member
Groups: Member

Joined: 7/11/2013
Posts: 11
Thank you very much. That worked perfectly.


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.