How do I dynamically add and remove a href

2

I have this href: <a href="/UpLoads/<%# Eval("DsPathDocumento")%>" class="linkUpload"><%# Eval("NmTipoDocumentoDown")%></a>

What I want is that I create a link only when I return from the procedure the DsPathDocumento and NmTipoDocumentoDown . This is in Asp.Net.

How do I do this?

    
asked by anonymous 28.11.2014 / 20:11

3 answers

1

Try this:

ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "script", "<script>$('#idLocal').append('<a href = \'url\'></a>');</script>", false);

Or this:

<asp:Button id="myid" runat="server" OnClientClick="$('#idLocal').append('<a href = \'url\'></a>')"/>

The code in js is using jQuery.

    
29.11.2014 / 01:05
0

There are several ways. One of them, without changing the code a lot, is to add in a a runat="server" and a id='nome' .

 <a href="/UpLoads/<%# Eval("DsPathDocumento")%>" runat="server" class="linkUpload"><%#Eval("NmTipoDocumentoDown")%></a>

Then, in your .cs you will have to reference your nome like any other control.

Another way is to put an object of type HyperLink and set its Visible="false" . You can set your NavigateUrl (link) of your .cs . Only view the link when you need it.

    
01.12.2014 / 16:21
0

By what looks like DsPathDocument is a string, so you can use something like:

I do not really like writing in ASP.NET using inline code, but since you're already using it, there's an alternative:

<% if(!String.IsNullOrEmpty(Eval("DsPathDocumento ").ToString())) { %>
    <a href="/UpLoads/<%# Eval("DsPathDocumento")%>" class="linkUpload"><%# Eval("NmTipoDocumentoDown")%></a>
<% } %>
    
01.12.2014 / 18:44