How I dynamically put and take out a href

Asked

Viewed 221 times

2

I got 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 DsPathDocumento and NmTipoDocumentoDown. This is on Asp.Net.

How do I do it?

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 js code is using jQuery.

0

From what looks like Dspathdocumento is a string, so you can use something like :

I don’t really like writing in ASP.NET using inline code, but since you’re already using it, here’s an alternative :

<% if(!String.IsNullOrEmpty(Eval("DsPathDocumento ").ToString())) { %>
    <a href="/UpLoads/<%# Eval("DsPathDocumento")%>" class="linkUpload"><%# Eval("NmTipoDocumentoDown")%></a>
<% } %>
  • I don’t like it either, but it’s already like this. I prefer the Behind code.

0

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

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

Hence, in his .cs will have to reference your nome like any other control.

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.