Answered by:
add <form> not works

Question
-
User1741069310 posted
Hi,
I don't know why a <form> added on page that included by MasterPage is not works
ie.
<%@ Page Title="" Language="C#" MasterPageFile="~/Master/MasterPage.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
<form id="form1" runat="server" action="test.aspx" method="get">
<input type="hidden" name="h" value="h"/>
<input id="Submit1" type="submit" value="submit" />
</form></asp:Content>
-----------------------------------------------------------------------------------
But, In normal web page is works
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<div>
<form id="form1" runat="server" action="test.aspx" method="get">
<input type="hidden" name="h" value="h"/>
<input id="Submit1" type="submit" value="submit" />
</form>
</div>
</body>
</html>Why?
Friday, June 1, 2018 9:52 AM
Answers
-
User632428103 posted
Hello fsze88,
because a master page has a form tag inside look on it ..
a page can have only one form tag
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Friday, June 1, 2018 10:02 AM -
User-330142929 posted
Hi fsze88,
Generally speaking, the webform can only contain one form whose runat=server. According to your description, it will contain multiple server forms when you set a sever form in master page.
The reason all server controls are placed inside <form> tag is to allow the WebForms engine to recognize them. It will block access from the code-behind when we set up multiple server forms.
Hope it helps you.
Best Regards,
Abraham
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, June 5, 2018 1:50 AM
All replies
-
User632428103 posted
Hello fsze88,
because a master page has a form tag inside look on it ..
a page can have only one form tag
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Friday, June 1, 2018 10:02 AM -
User-330142929 posted
Hi fsze88,
Generally speaking, the webform can only contain one form whose runat=server. According to your description, it will contain multiple server forms when you set a sever form in master page.
The reason all server controls are placed inside <form> tag is to allow the WebForms engine to recognize them. It will block access from the code-behind when we set up multiple server forms.
Hope it helps you.
Best Regards,
Abraham
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, June 5, 2018 1:50 AM