简体   繁体   中英

Buttons in master page ASP.NET 4

Every time I try to add a button to my master page, I got this error : Control 'Button1' of type 'Button' must be placed inside a form tag with runat=server.

PS : the button is inside a div tag with runat=server !

It's inside a div tag. It must be inside a form tag, like this:

<form runat="server">
 // button here
</form>

Inside the body tag, you have a form tag like this

 <body>
    <form id="form1" runat="server">
    <div>
    </div>
    </form>
 </body>

All server controls must appear within a <form> tag, and the <form> tag must contain the runat="server" attribute.

For more information about the form tag..Check this page

Now is it okay to you (if you want to keep your Div )

<form Id="MyForm" runat="server">
      <div Id="MyDiv" runat="server">
         // Here your HTML.
      </div>
</form>

This is because in ASP.NET one page should have one Form with runat = "server" tag and in Master page we keep this Form tag and in content page we keep other required controls.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM