I have the below code:
<asp:Content ID="HeadContent" runat="server" ContentPlaceHolderID="HeadContent">
<script type="text/javascript">
function SetText(id) {
if (Button2.value == "Disable automatic page refresh")
Button2.value = "Automatic Refresh Disabled";
return false;
}
</script>
</asp:Content>
<asp:Button ID="Button2" runat="server" Text="Disable automatic page refresh" OnClick="Button2_Click" OnClientClick="return SetText(this)" />
When I click the button though, the button name does not change, but the code behind C# does still work as normal. Can anyone point me in the right direction? I thought it might have been the OnClick event, but after removing it, it still didn’t work. I also tried changing the OnClick to OnServerClick just in case but to no avail.
You are using the name of the button instead of the reference to the button that is sent to the method. Use the reference: