Attachment view link

1

I have a hyperlink to view my attachment. My attachment is on the server and your wallet is written to the database. I am wanting at the time that the person click on Hyerlink open a new tab and present the attachment.

Follow my code

function popuplista(c) {
    popupwide("'"+ c +"'");
}

<asp:HyperLink ID="lblMensagemAnexo" runat="server" NavigateUrl='<%# Eval("Anexo") %>'
                        Text="Clique aqui para ver o anexo" Width="250px" Visible="false" Target="_blank"></asp:HyperLink>

lblMensagemAnexo.NavigateUrl = "javascript:popuplista('" + dt.Rows[0]["Anexo"].ToString() + "');";
    
asked by anonymous 25.08.2014 / 19:27

2 answers

1

Marconi, You do not need to use a WebControl or javascript to do this. Instead try something simpler like:

<a href='<%#Eval("Anexo")%>' download target="_blank">Clique aqui para ver o anexo</a>
  • download forces the browser to download the content of the link. (does not work in IE)
  • target is used as fallback
26.08.2014 / 16:26
1

A while ago I had this problem too.

After searching, I could not find a way to do this through ASP.NET.

The method I was able to do to solve the problem was to add an event to the LinkButton click:

<asp:LinkButton ID="lblMensagemAnexo" runat="server" CommandArgument='<%# Eval("Anexo") %>' Text="Clique aqui para ver o anexo" Width="250px" Visible="false"  OnClick="lblMensagemAnexo_Click"></asp:LinkButton>

And then in the Event, use JavaScript to open a new tab.

protected void lblMensagemAnexo_Click(object sender, EventArgs e)
{
    LinkButton btn = (LinkButton)(sender);
    string url= btn.CommandArgument;
    Response.Write("<script>window.open('" +url+"','_blank');</script>");
}

Just pointing out was the way I found it to solve the problem.

    
25.08.2014 / 19:37