I'm making a ASP.NET Web Forms application. I am trying to have a simple way where I can access several controls on the form.
I am trying to access html buttons' serverClick event but it has not been working and only worked on a single button per page.
I first tried to use this code to get the click event when the HTML button was clicked. This is the code for the HTML button.
<form runat="server">
<div class="btn-container">
<a runat="server" onserverclick="infobutton_Click" class="inf-btn" exc-content="inf_button" id="infoButton">Click Here for More Information</a>
</div>
</form>
This code gets the button's click event and displays a sample message box.
Protected Sub infoButton_Click(ByVal sender As Object, ByVal e As EventArgs)
ScriptManager.RegisterClientScriptBlock(Me, Me.[GetType](), "alertMessage", "alert('" & "The Button Was Clicked" & "')", True) 'Displays a JavaScript Alert
End Sub
This code works fine for one button per page, however, I want to use multiple buttons on one page. If I remove the <form> tag, the button click event does not register. If I add a <form> tag for each and every button, it reports an error that there cannot be multiple <form> tags. If I enclose the whole page with a <form> tag, the error reports that the configuration is "corrupted".
This would be straightforward if I had a ASP.NET button control (<asp:button>), but I cannot convert all elements on the page.
I'm not sure what is wrong as all information online says it is correct. Is there any way I can fix this?