Mona Coder
Mona Coder

Reputation: 6316

How to open a PDF file on click?

I have a button like below which in charge of opening an image in top of the ASP.NET application.

<asp:Button 
    ID="MatrixButton" 
    runat="server" 
    Text="Risk Matrix" 
    CausesValidation="False"
    OnClientClick="openImageDoc('Images/RiskMatrixCapitalAllocation.jpg', 'RiskMatrix')"/>

Now I need to have another button to do the same function but this time opens a PDF file

<asp:Button 
    ID="AnalysisButton" 
    runat="server" 
    Text="Risk Analysis" 
    CausesValidation="False"
    OnClientClick="openPDFDoc('PDF/RiskAnalysis.pdf.jpg', 'RiskAnalysis')"/>

Here is the JavaScript:

 function openPDFDoc(filePath, titleName) {
    var newUrl = baseUrl + filePath;
    window.open(newUrl, titleName, 'width=900,height=800,scrollbars=1');
}

Upvotes: 0

Views: 1394

Answers (1)

Sudhakar Tillapudi
Sudhakar Tillapudi

Reputation: 26209

You need to remove the extension .jpg from the path.

Replace This:

PDF/RiskAnalysis.pdf.jpg

With This:

PDF/RiskAnalysis.pdf

Upvotes: 1

Related Questions