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?
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.