How to open Pdf file in a new Window upon HyperLink NavigateUrl RRS feed

  • Question

  • User2092378267 posted

    I have a HyperLink like below:

    <asp: HyperLink runat="server" ID="PdfHyperLink" Target="_blank" NavigateUrl='<%# (Eval("FilePath")) %>' />

    Upon Clicking on HyperLink, I need to show Pdf file in a new window and, this file is coming from FilePath on Code Behind.
    Code Behind:

    protected void btn_Click (object sender, EventArgs e)
     Entities.Masters.Country country = new Entities.Masters.Country();
     country.Id = Convert.ToInt32(CountryIdHiddenField.Value);
     Country_Bal countryBal = new Country_Bal();
     String FilePath = countryBal.GetCountriesPdf(country);
    PdfHyperLink.NavigateUrl = FilePath; }

    I'm getting the file name in  .pdf format on FilePath upon debugging. but HyperLink is not binding to this FilePath of btn_Click method to show pdf file in a new window.

    I have many cases in Business Access Layer like below, I'm getting the intended FilePath on Code Behind method, upon the selected country, and this selected country pdf file should be shown on the new window. But unable to bind the HyperLink to CodeBehind to Choose FilePath.

    public string GetCountriesPdf(Entities.Masters.Country country)
    string FilePath = ConfigurationManager.AppSettings["GetCountriesPdf"];
    case 1:
    return FilePath+= "Country file"+".pdf";

    Sunday, August 30, 2020 7:01 AM

All replies

  • User409696431 posted

    If you are setting the hyperlink NavigateURL in code behind, remove the

    NavigateUrl='<%# (Eval("FilePath")) %>'

    from the HyperLink code in the page.

    It's not clear what your btn_Click code is attached to, so I can't comment further.

    Sunday, August 30, 2020 1:40 PM