Click here to Skip to main content
15,911,306 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I created the imageBtn_Click(object sender, ImageClickEventArgs e) for 2 pages to open a PDF file. It works well for 1 page but not for another one even though I used the identical code.
C#
void imageBtn_Click(object sender, ImageClickEventArgs e) {
    string pdfPath = g.sFolder + "GIS Strategic Plan Final 080314.pdf";
    WebClient client = new WebClient();
    Byte[] buffer = client.DownloadData(pdfPath);
    Response.ContentType = "application/pdf";
    Response.AddHeader("content-length", buffer.Length.ToString());
    Response.BinaryWrite(buffer);
}

The error I got is:
Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. I wonder why this piece of code got failure for one of the page. Please help if you can. Thanks.
Posted

It seems like problem is with your file name. Your file name has spaces which my be an issue. Try by eclosing your file path by double quotes as below.
C#
string pdfPath = "\"" +  g.sFolder + "GIS Strategic Plan Final 080314.pdf\"";
 
Share this answer
 
RaisKazi: Thanks for your post. Checked but it is not the case. As mentioned in my inital post, I transplaned the exact the same code from another aspx. file (in the same project). Another one works fine. Somethin is stranger to me.
I re-checked my code in both aspx (1 works well but another 1 not). The code for the one working well is below:
VB
<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/Images/PDF.jpg"
    onclick="ImageButton1_Click" style="height: 16px"/>


and the code behind:
C#
protected void ImageButton1_Click(object sender, ImageClickEventArgs e) {
    WebClient client = new WebClient();
    Byte[] buffer = client.DownloadData(path);
    Response.ContentType = "application/pdf";
    Response.AddHeader("content-length", buffer.Length.ToString());
    Response.BinaryWrite(buffer);
}


The one does not working likes that below:
XML
<div>
    <asp:ScriptManager ID="ScriptManager1" runat="server"/>

    <asp:updatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <asp:PlaceHolder runat="server" ID="placeholder1"/>
        </ContentTemplate>
    </asp:updatePanel>
</div>


The code behind runs the same code in the method:
public void imageBtn_Click(object sender, ImageClickEventArgs e)   {
    ......
    string pdfPath = g.sFolder + myPdf;
    WebClient client = new WebClient();
    Byte[] buffer = client.DownloadData(pdfPath);
    Response.ContentType = "application/pdf";
    Response.AddHeader("content-length", buffer.Length.ToString());
    Response.BinaryWrite(buffer);
}

How can this problem be solved? Thanks if you can provide your hint.
 
Share this answer
 
v2
The problem has been solved by referring the post at .[^]. I added
ScriptManager scriptManager = ScriptManager.GetCurrent(this.Page);
...
scriptManager.RegisterPostBackControl(imageBtn);
in the Page_Load().
 
Share this answer
 

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