I am trying to add a view inside a Web form and its fine to show data. But I do a post it break. I have used LINK sample which I found on sof but it wont work for POST Request. Always throwing a MAC fail error.
Asked
Active
Viewed 101 times
1 Answers
0
Webforms typically uses a single form for the entire page. But HTML does not support nested forms, so if you put another form onto the page via MVC partial view, you need to ensure the partial view is not rendered inside of your <form runat="server">
tag.
Here is an example of using multiple forms with Webforms.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<fieldset>
<legend>ASP.NET web form (POST)</legend>
<asp:Label runat="server" AssociatedControlID="txtSearch">Name: </asp:Label><asp:TextBox runat="server" ID="txtSearch" /><asp:Button runat="server" ID="btnSend" Text="Search" OnClick="btnSend_Click" />
</fieldset>
</form>
<form method="get" action="Search.aspx">
<fieldset>
<legend>Regular HTML form using GET</legend>
<label for="name-text">Name: </label><input type="text" id="name-text" name="q" /><input type="submit" value="Search" />
</fieldset>
</form>
<form method="post" action="Search.aspx">
<fieldset>
<legend>Regular HTML form using POST</legend>
<label for="name-text2">Name: </label><input type="text" id="name-text2" name="q" /><input type="submit" value="Search" />
</fieldset>
</form>
</body>
</html>
NOTE: If your main webforms form is declared in a master page, you will need to render your MVC form inside of a separate
ContentPlaceHolder
control so the forms are not nested.
<!DOCTYPE HTML>
<html id="Html1" runat="server" xmlns="http://www.w3.org/1999/xhtml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.w3.org/1999/xhtml http://www.w3.org/MarkUp/SCHEMA/xhtml-rdfa-1.xsd" xmlns:og="http://opengraphprotocol.org/schema/" >
<head id="Head1" runat="server">
<title>My Site</title>
</head>
<body id="Body1" runat="server">
<form id="frmMain" runat="server">
<!-- form for Webforms -->
<asp:ContentPlaceHolder id="MainContent" runat="server">
</asp:ContentPlaceHolder>
</form>
<!-- placeholder for external forms -->
<asp:ContentPlaceHolder ID="OutsideOfForm" runat="server">
</asp:ContentPlaceHolder>
</body>
</html>

Community
- 1
- 1

NightOwl888
- 55,572
- 24
- 139
- 212