Trying to put two runat=server forms in one web form asp.net

583 Views Asked by At

i'm building a site for course project in Web forms asp.net and i did a master page for all the website i want to have a text box that acts as a search in the website but it needs to be in

<form runat="server">

this is master code

<html>
    <div id="topContent">
        <head runat="server">
            <form runat="server">
                <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
                <asp:ContentPlaceHolder ID="head" runat="server"></asp:ContentPlaceHolder>
                <title>Dor Lugasi Guitar Shop</title>
                <link href="Styles.css" rel="stylesheet" type="text/css" />
                <right>
                <img src="../Images/logobk2.png" alt="Powered by DLG!" class="auto-style7"/><br />
                <center id="headdiv">
                    <asp:LinkButton ID="lnkHome" runat="server" PostBackUrl="~/Pages/Home.aspx" >Home</asp:LinkButton>
                    <asp:LinkButton ID="lnkLogin" runat="server" PostBackUrl="~/Pages/Login.aspx">Login</asp:LinkButton>
                    <asp:LinkButton ID="lnkContact" runat="server" PostBackUrl="~/Pages/Contact.aspx" >Contact</asp:LinkButton>
                    <asp:LinkButton ID="lnkGuitarLab" runat="server" PostBackUrl="~/Pages/GuitarLab.aspx">Guitar Lab</asp:LinkButton>
                    <asp:ImageButton style="float:left;margin-left:10px;" ID="btnCart" runat="server" Height="55px" ImageUrl="~/Images/cart.png" Width="55px" PostBackUrl="~/Pages/Cart.aspx" />
                    <asp:TextBox ID="txtSearch" runat="server" BackColor="Silver" BorderColor="Black" TextMode="Search" placeholder="               Search" onkeypress="txtSearch"></asp:TextBox>
                    <asp:ImageButton ID="btnSearch" runat="server" ImageUrl="~/Images/src.png" OnClick="btnSearch_Click" Width="25px" />
                </center>
                <center id="headdiv" class="auto-style6">
                    <asp:Label style="float:left;margin-left:10px;" ID="lblLoggedUser" runat="server" Font-Bold="True" Font-Size="Large" ForeColor="Red"></asp:Label>
                    <asp:LinkButton ID="btnLogOut" runat="server" OnClick="btnLogOut_Click" Visible="False" CssClass="auto-style5" Height="24px" Width="99px">Log Out</asp:LinkButton>
                    <asp:LinkButton style="float:right;margin-right:10px;" ID="lnkManageProducts" runat="server" PostBackUrl="~/Pages/ManageProducts.aspx">Manage Products</asp:LinkButton>
                    &nbsp;&nbsp;
                    <asp:LinkButton style="float:right;margin-right:10px;" ID="lnkManageUsers" runat="server" PostBackUrl="~/Pages/ManageUsers.aspx">Manage Users</asp:LinkButton>
                </center>
            </form>
        </head>
    </div>
    <body id="body">
        <form runat="server">
            &nbsp;&nbsp;
            <center>
                <asp:contentplaceholder id="ContentPlaceHolder1" runat="server">
                </asp:contentplaceholder>
            </center>
            <footer id="footer" class="auto-style3">
                </left>
                <img src="../Images/logowhite.png" alt="Powered by ASP.NET!" />
            </footer>
        </form>
    </body>
</html>  

but im getting a:

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

before i added this search textbox and button i had

<form runat="server">
<html>
...
<head>.....</head>
<body>....</body>
<footer>.....</footer>

</html>
</form>

and it worked but at the login page when i pressed Enter it applied to the search form instead of the login form

1

There are 1 best solutions below

2
Dor Lugasi On

eventually i ended up making a single form for the page and just put the specific form that had buttons in

<asp:Panel ID="search_panel" runat="server" DefaultButton="btnSearch">
                    <asp:TextBox ID="txtSearch" runat="server" BackColor="Silver" BorderColor="Black" TextMode="Search" placeholder="               Search" onkeypress="txtSearch"></asp:TextBox>     
                    <asp:ImageButton ID="btnSearch" runat="server" ImageUrl="~/Images/src.png" OnClick="btnSearch_Click" Width="25px" />                     
                    </asp:Panel>

i hope thats the right way