How to prevent hyperlink binding

Is it possible to prevent the binding of the asp.net Hyperlink control, i.e. so that it appears as a shortcut, without having to replace the label control? Maybe use CSS or set an attribute?

I know that designating it as disabled works, but then it appears in different ways (greyed out).

To clarify my point, I have a list of usernames at the top of my page that are dynamically created using a user control. In most cases, these names are associated with email. However, if the user is disconnected, the name is grayed out, but currently it still refers to the email page. I want these disconnected users not to be referenced.

I know that in fact I have to replace them with a shortcut, but this does not look as elegant as just removing CSS links that talk about linking capabilities (if possible). They are already displayed in a different color, so it is obvious that they are disconnected users. I just need to disable the link.

+3
source share
11 answers

This seems to work for jQuery. Just give a specific class name to all the HyperLink controls that you want to remove the URL from, and then apply the following jQuery snippet at the bottom of the page:

$(document).ready(function() {
    $('a.NoLink').removeAttr('href')
});

All HyperLink controls with the class name "NoLink" will be automatically removed from all URLs, and the link will be nothing more than text.

A single line of jQuery can solve your problem.

+6

, , . ?

? <span> HTML , .

onClick-Event, " false"; - JS .

: ? - , ?

? , , , : -)

+4

Hyperlink "a" /a, , . CSS, .

, System.Web.UI.WebControls.HyperLink Render

protected override void Render(HtmlTextWriter writer)
        {
            if (Enabled)
                base.Render(writer);
            else
            {
                writer.RenderBeginTag(HtmlTextWriterTag.Span);
                writer.Write(Text);
                writer.RenderEndTag(HtmlTextWriterTag.Span);
            }
        }

     }

, .

asp: CustomHyperlink asp: CustomButton . .

+3

, , CSS "a", :

a: link, visited, hover, active {
    text-decoration: none;
}

"" , , .

@pilif , , .

+2

:

onclick="return false;"  

, href "#". - css, . :

a.dummy {  
    cursor:default;  
}  
+2

, "javascript: void (0);", ..:

< a href= "javascript: void (0);" > foo </a>

+2

, , : ", ( )", .

+2

databind asp.net, NavigateUrl, .

0

Have you tried setting the non NavigateUrl property? If this is not specified, it can simply be displayed as a range.

0
source

.fusion-link-wrapper {pointer-events: none; }

0
source

Another solution is to apply this class to your hyperlink.

.avoid-clicks {
  pointer-events: none;
}
0
source

Source: https://habr.com/ru/post/1696726/


All Articles