2
votes

I need to disable anchor tag using button click event. I handled both server-side and client-side events for my requirement. I modified the 'href' attribute in client-side click event as follows.

[ASPX]

 <asp:Button ID="Button1" runat="server" Text="Disable" OnClick="disable"  CausesValidation="false" OnClientClick="disable();"  />

[Script]

     function disable() {
        $('a.ClassName').attr("href", "#")
    }

It gets set properly. But after the server-side process, anchor tag again sets with the old href attributes. How to resolve this?

2
If the client side part works as intended, why just modify the href attribute on serverside after the "server side process"?Johan

2 Answers

2
votes

When you PostBack to the server, a fresh page is rendered.

Any changes you made via javascript will be lost.

You should detect the condition(button being pressed earlier), at server side and make the necessary changes to url server side too.

You can store this state change in a hidden input and get it at server side.

0
votes

you have to disable the link as soon as the page loaded useing ,

preventDefault();

so try to do something like this ,

function disable_link(event) {

    event.preventDefault();
    return false;
}

but instead just bind it to the specific element that you want