0

I would like to use the LinkButton Control because it has a 'click' event built in which can be used to add functionality to a page. Unfortunately the LinkButton insists on doing a postback every time it is clicked. Is there a way to avoid this?

public void displayTutorial_Click(object sender, System.EventArgs e)
{

    if (lnkView.CommandName == "pdffile")
    {
        try
        {
            if (Page.IsPostBack)
            {
                Response.Write(string.Format("<script>window.open('{0}','_blank');</script>", "FileUploads/EpilepsyExpertMappingResults.pdf"));
            }

        }
        catch (Exception ex)
        {
            ExceptionManager.Publish(ex);
        }
    }

} 

in aspx page:

<asp:LinkButton ID="lnkView" runat="server" CommandName="pdffile"  onclick="displayTutorial_Click" ForeColor="#2aa7f9">Click here</asp:LinkButton>
Olivier De Meulder
  • 2,493
  • 3
  • 25
  • 30

1 Answers1

0

Do not use the click event on your link button, but set the ClientClick property to "window.open('FileUploads/EpilepsyExpertMappingResults.pdf','_blank');return false;"

It saves you the post back to execute the clientscript

Niels V
  • 1,005
  • 8
  • 11