Disable snapping with button click

I need to disable anchor tag using click event. For my requirement, I was handling both server-side and client-side events. I changed the "href" attribute in the 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 installs correctly. But after a server side process, the anchor tag sets the old href attributes again. How to solve this problem?

+3


source to share


2 answers


When you submit PostBack to the server, a new page is displayed.

Any changes made with javascript will be lost.



You have to define the condition (the button pressed earlier) on the server side and make the necessary changes to the server url.

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

+3


source


you need to disable the link as soon as the page loads,

preventDefault();

      

try doing something like this,



function disable_link(event) {

    event.preventDefault();
    return false;
}

      

but instead just bind it to the specific element you want

+1


source







All Articles