HTML Question

Form and buttons issues with ASP.NET

I am trying to add two buttons in an array which are going to run functions to accept or refuse some kind of requests in an array, like so :

This is an example of what my array looks like

My first trial was a code like the following :

<td class="actions">
<form method="post" action="approve.aspx" runat="server">
<asp:Button ID="buttonyes" class="buttonyes" CommandArgument='<%: request.ID %>' CommandName="AcceptRequest" OnCommand="ButtonPressed" runat="server"/>
</form>
<form method="post" action="refuse.aspx" runat="server">
<asp:Button ID="buttonno" class="buttonno" CommandArgument='<%= request.ID %>' CommandName="RefuseRequest" OnCommand="ButtonPressed" runat="server"/>
</form>
</td>


But when I tried to open the page, this error rose up :


A page can have only one server-side Form tag.


So I tried to remove one form, and put the two buttons in it, like so :

<td class="actions">
<form method="post" action="approve.aspx" runat="server">
<asp:Button ID="buttonyes" class="buttonyes" CommandArgument='<%: request.ID %>' CommandName="AcceptRequest" OnCommand="ButtonPressed" runat="server"/>
<asp:Button ID="buttonno" class="buttonno" CommandArgument='<%= request.ID %>' CommandName="RefuseRequest" OnCommand="ButtonPressed" runat="server"/>
</form>
</td>


But I get exactly the same error, which is kind of logic since there might be many entries in my array, and each one of them should have those two buttons, so I changed my code like so :

<td class="actions">
<asp:Button ID="buttonyes" class="buttonyes" CommandArgument='<%: request.ID %>' CommandName="AcceptRequest" OnCommand="ButtonPressed" runat="server"/>
<asp:Button ID="buttonno" class="buttonno" CommandArgument='<%= request.ID %>' CommandName="RefuseRequest" OnCommand="ButtonPressed" runat="server"/>
</td>


But then, I get


Control 'buttonyes' of type 'Button' must be placed inside a form tag with runat=server.


I can't figure out how to fix my issue, and since I am quite new to ASP.NET and searched in a lot of various ways, I would like to know if anybody knows how I can fix this problem.

Answer Source

Move the form higher in the page. If it's inside table with multiple rows, then you'll end up with a form for each row. Wrap the entire table in the form like so:

<form method="post" action="approve.aspx" runat="server">
    ...
    <tr>
        ...
        <td class="actions">
            <asp:Button ID="buttonyes" class="buttonyes" CommandArgument='<%: request.ID %>' CommandName="AcceptRequest" OnCommand="ButtonPressed" runat="server"/>
            <asp:Button ID="buttonno" class="buttonno" CommandArgument='<%= request.ID %>' CommandName="RefuseRequest" OnCommand="ButtonPressed" runat="server"/>
        </td>
    <tr>
</form>