I have the following components:
<asp:button runat="server" ID="testjavascript" Enabled="false" OnClientClick="return false;"/>
<asp:button runat="server" ID="testcodebehind" OnClick="testfunction" />
I have this javascript class function:
$('.close').on('click', function() {
alert("it works!");
return false;
});
I have the buttons inside an update panel and it is working asynchronously. When clicked, testcodebehind enables and adds the class "close" to the testjavascript button:
testjavascript.Enabled = true;
testjavascript.Attributes.Add("class", "close");
Now here is my problem, when I click on testcodebehind
, it works and testjavascript
becomes enabled. testjavasctipt
also gets the class "close" (F12 - inspect), but clicking on it does not trigger the javascript function! I know that the function works because if I change the testjavascript
button and manually add the class close to it, then it works.
I checked online (for hours) and found several links, one of them was this: Click event doesn't work on dynamically generated elements
Many of the other links were basically the same. But I already have .on!
Any help would be greatly appreciated. Thank you!