Click here to Skip to main content
15,888,341 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello,

I am trying to load a pdf document into an iFrame from code behind. I am using the following code in code behind on Page Load:

C#
if (Session["Document"].ToString() != string.Empty)
        {
            string document = Session["Document"].ToString();
            pdfIframe.Attributes.Add("src", document);
        }


It works perfectly when I run it from inside Visual Studio 10 using the internal web-server, but it does not work at all when it is uploaded to the website (it throws an error page) Everything else (eg: database, queries, etc.) works fine.
Any help appreciated.

What I have tried:

I have done a Google search and tried a few different code variations. I changed the web.config file to an earlier version. I have tried to run it in Firefox and IE. No luck.
Posted
Updated 14-Mar-17 10:34am
Comments
Afzaal Ahmad Zeeshan 11-Mar-17 17:55pm    
Which error?

Perhaps, it requires some add-on?
PDTUM 12-Mar-17 12:26pm    
Thank you Afzaal, It is a Runtime Error and I did not see the actual error in the error page. Not sure how to do that but I will look into it today. I will post what it said below.

As to "some add on" ... honestly, that's really way too vague for an answer. As stated, I am using the internal asp.net browser function that comes with Visual Studio 10, and it works perfectly. So I would "assume" that someone with more expertise than I have about Browsers could tell me if I need to add something to the program for it work on standard type browsers. If that's the case, then knowing which add on is required would be the answer that I am looking for. The only other way I can think of to resolve the problem is not to use pdf's and instead do a 'database' pull for the information as text and post it to a text area (not very pretty); and that seems like a very poor compromise. Thanks again for your input. I'm all ears if you can follow up on this. Best Regards, Pat
ZurdoDev 13-Mar-17 15:49pm    
You need to find the error or else there is no way to help.

1 solution

Following Up; although I am still trying to get a read out of the page error (unsuccessful so far), I thought of switching to a Google Docs reader to see if the error might be with the Adobe reader (not uncommon). Again, it works perfectly in the VS 2010 environment, but it still throws a runtime error of some kind since it is now referring to an error page that I have put in to the web.config file. I'll show the new code below, buy I do not think it is a coding problem (this coming from someone that obviously cannot fix it!). I feel it has something to do with the web.config file (just a hunch if you will). PLEASE, as I continue to try to get an error readout, someone MUST have seen an issue like this before. Any idea's are welcome. Thank you, Pat.

C#
//Using iFrame with Google Docs
        if (Session["Document"].ToString() != string.Empty)
        {
            string document = Session["Document"].ToString();
            string pdfPage = "http://docs.google.com/gview?url=" + document + "&embedded=true";
            pdfFrame.Attributes.Add("src", pdfPage);
        }
        else
        {
            ClientScriptManager script = Page.ClientScript;
            if (!script.IsClientScriptBlockRegistered(this.GetType(), "Alert"))
            {
                script.RegisterClientScriptBlock(this.GetType(), "Alert", "alert('Sorry, this document cannot be found. ')", true);
                return;
            }
        }
 
Share this answer
 
Comments
PDTUM 15-Mar-17 15:43pm    
OK Gentleman; For those following this thread and were nice enough to point me in the right direction, I was able to finally figure out how to get the error to read out and then I could of course fix it once I knew what it was. So... now, although there is no error, the pages simply don't work. And that goes for two types of pages. In the VS program, I pass a string to an i-Frame that has the location and file name in it through the code behind. I have now tried this in two ways; one uses the i-Frame directly, as in the first example above, and then I tried it with Google Docs embedded, as in the second example. Both work in the Dev Studio software, neither works as a stand alone web page on the Net. Also, the string source makes no difference. One way is to obtain it through an Sql query, the other passes the string from a combo box ... neither one works. I am exasperated with this project. Why? Again, I ask for your help. Thank you, Pat.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900