Link to home
Start Free TrialLog in
Avatar of mjoseph23
mjoseph23

asked on

Does anyone know how to unload a pdf from a frame/webpage that is drawn by ceTe Dynamic PDF Merger?

I am experiencing some tricky session and frame behavior. I have a page A with a frame B in it. A session variable is passed from the main page A to the frame page B in order to display a pdf in the frame B. After the main page A is done passing the session variable to the frame page B I remove the variable from the session. When I leave the main page A and go back to the page C with the link to the main page A and then click a link to a second page D which is similar to page A. second main page D has a frame page E that is for some odd reason displaying the pdf from the first frame page B. I have tried everything
protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            LoadPrimaryQapPDF();
        }
    }
 
    protected void LoadPrimaryQapPDF()
    {
        string filepath = "";
 
        if (!String.IsNullOrEmpty(Session["file"].ToString()))
        {
            filepath = Session["file"].ToString();
        }
 
        if (!String.IsNullOrEmpty(filepath))
        {
            //Create a PDF document
            MergeDocument document = new MergeDocument(@filepath);
 
            // Create a page and add it to the document 
            ceTe.DynamicPDF.Page page = new ceTe.DynamicPDF.Page();
            document.Pages.Add(page);
 
            // Outputs the document to the current web page
            document.DrawToWeb();
 
            Session.Remove("file");
        }
    }
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Geoff Sutton
Geoff Sutton
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mjoseph23
mjoseph23

ASKER

I have tried an empty string with the session. Currently I have a blank page hardcoded in the frame, but I did not think about using a query string in code behind. These are the steps I take to load the pdf. On Page A, the user uploads a file through the file upload control, then they can press buttons save or view. When they do that, page A takes the file location uploaded in the control and stores it in a session variable. Pressing the buttons causes some sort of postback on page B in the frame. When page B loads it takes the stored session variable containing the file location and passes it to the ceTe dynamic pdf generator then the generator draws the pdf on page B.

/***************page A******************/
 
    protected void btnView_Click(object sender, EventArgs e)
    {
        Session["file"] = "";
 
        //iframe1.Visible = false;
 
        if (FileUpload1.HasFile)
        {
            Label1.Text = "";
 
            string fileExt = System.IO.Path.GetExtension(FileUpload1.FileName);
 
            if (fileExt == ".pdf")
            {
                try
                {
                    //iframe1.Visible = true;
 
                    string file = FileUpload1.PostedFile.FileName.Substring(3, FileUpload1.PostedFile.FileName.Length - 3);
                    string appendedfile = "\\\\msgsap4n39r\\88mdg\\" + file;
 
                    Session["file"] = appendedfile;
 
                    FilePath.InnerHtml = Session["file"].ToString();
                }
                catch (Exception ex)
                {
                    Label1.Text = "Error: " + ex.Message.ToString();
                }
            }
            else
            {
                Label1.Text = "Only .pdf files allowed!";
            }
        }
        else
        {
            Label1.Text = "You have not specified a file.";
        }
    }
 
/**************page B*******************/
    protected void LoadPrimaryQapPDF()
    {
        string filepath = "";
 
        if (!String.IsNullOrEmpty(Session["file"].ToString()))
        {
            filepath = Session["file"].ToString();
        }
 
        if (!String.IsNullOrEmpty(filepath))
        {
            //Create a PDF document
            MergeDocument document = new MergeDocument(@filepath);
 
            // Create a page and add it to the document 
            ceTe.DynamicPDF.Page page = new ceTe.DynamicPDF.Page();
            document.Pages.Add(page);
 
            // Outputs the document to the current web page
            document.DrawToWeb(false);
 
            Session.Remove("file");
        }
    }

Open in new window

I must admit then that I am a loss.  i would start by running some simple tests - What is session["file"] set to before you pass it from A, and when you receive it at B?  Rather than using session, how about javascript?  http://www.simiandesign.com/blog-fu/2005/08/javascript_acro.php  Use that to pass the value across then initiate a postback of some sort (session variables are not, I have found, incredibly reliable - I prefer querystrings, post variables or viewstate where possible).
Yes, the query string solved the problem. Thanks!

iframe1.Attributes["src"] = "QapAppointmentLetterPDFBottom.aspx?file=" + appendedfile;