[英]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. 每次尝试将按钮添加到母版页时,都会出现此错误:必须将类型为“按钮”的控件“按钮1”放置在带有runat = server的表单标记中。
PS : the button is inside a div tag with runat=server ! PS:按钮位于带有runat = server的div标签中!
It's inside a div
tag. 它在
div
标签内。 It must be inside a form
tag, like this: 它必须在
form
标签内,如下所示:
<form runat="server">
// button here
</form>
Inside the body tag, you have a form tag like this 在body标签内,您有一个这样的表单标签
<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. 所有服务器控件必须出现在
<form>
标记内,并且<form>
标记必须包含runat =“ server”属性。
For more information about the form tag..Check this page 有关表单标签的更多信息。检查此页
Now is it okay to you (if you want to keep your Div
) 现在可以了(如果您想保留
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. 这是因为在ASP.NET中,一页应具有带有
runat = "server"
标签的一个Form
,而在Master页中,我们保留此Form
标签,而在内容页中,我们保留其他必需的控件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.