Problem using form runat=server with master pages?

时间:2021-08-08 00:32:11

I have a master page with two ContentPlaceHolders.

我有一个包含两个ContentPlaceHolders的母版页。

I have a default page.aspx which uses this master page.

我有一个使用此母版页的默认page.aspx。

In the default page one ContentHolder has a TreeView and the other has a GridView.

在默认页面中,一个ContentHolder具有TreeView,另一个具有GridView。

Now i need to display both of them together and both require <form runat="server">.

现在我需要将它们显示在一起,并且都需要

But the issue is that i cant have two instances of <form runat="server"> in a single page.

但问题是我不能在一个页面中有两个

的实例。

I tried putting <form runat="server"> on the master page but then the TreeViewand GridView functionality stops working.....

我尝试在主页面上放置

,然后TreeView和GridView功能停止工作.....

Please help me as to what can i do to solve this.

请帮助我,我该怎么做才能解决这个问题。

Page File:

<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="GridViewPg1.aspx.cs" Inherits="GridViewPg1" %>

<%@ Register assembly="obout_Grid_NET" namespace="Obout.Grid" tagprefix="cc1" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
   <form id="form1" runat="server">   
   <asp:Panel ID="Panel1" runat="server" ScrollBars="Vertical">

   <a style="color: #000000; font-weight: bold;">SumooHServer</a>
       <p>&nbsp;<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
           ConnectionString="<%$ ConnectionStrings:SumooHAgentDBConnectionString %>" 
           SelectCommand="SELECT DISTINCT [MachineGroupName], [MachineGroupID] FROM [MachineGroups]">
       </asp:SqlDataSource>
       <asp:SqlDataSource ID="SqlDataSource2" runat="server" 
           ConnectionString="<%$ ConnectionStrings:SumooHAgentDBConnectionString %>" 
           SelectCommand="SELECT DISTINCT [PolicyID], [PolicyName] FROM [Policies]">
       </asp:SqlDataSource>
       <asp:TreeView ID="TreeView2" runat="server" 
           ontreenodepopulate="TreeView2_TreeNodePopulate">
           <Nodes>
               <asp:TreeNode NavigateUrl="~/GridViewPg1.aspx" PopulateOnDemand="True" 
                   Text="Machine Group" Value="Machine Group"></asp:TreeNode>
           </Nodes>
       </asp:TreeView>
       <asp:TreeView ID="TreeView3" runat="server" 
           ontreenodepopulate="TreeView3_TreeNodePopulate">
           <Nodes>
               <asp:TreeNode PopulateOnDemand="True" Text="Policies" Value="Policies">
               </asp:TreeNode>
           </Nodes>
       </asp:TreeView>
       </p></asp:Panel>
</form>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder2" Runat="Server">

<asp:Panel ID="Panel2" runat="server" ScrollBars="None" Width="100%">
    <cc1:Grid ID="Grid1" runat="server" AllowFiltering="True" 
    AllowGrouping="True" DataSourceID="SqlDataSource3">
    </cc1:Grid>
    <asp:SqlDataSource ID="SqlDataSource3" runat="server" 
    ConnectionString="<%$ ConnectionStrings:SumooHAgentDBConnectionString %>" 
    SelectCommand="SELECT * FROM [MachineGroups]"></asp:SqlDataSource>
</asp:Panel>

</asp:Content>

Masterpage file:

<%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="MasterPage" %>

<!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>
<title>SumooH</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="style.css" />
</head>

<body>

  <div id="wrapper">
    <div id="header" 
          style="border-bottom-style: solid; border-bottom-color: #0000FF; border-bottom-width: medium">
    </div>

     <div id="left-content" 
          style="border-right: thin ridge #000000; top: 104px;">

          <asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">

        </asp:ContentPlaceHolder>
    </div>
    <div id="content-wrapper">
      <div id="content-inner">


        <asp:ContentPlaceHolder id="ContentPlaceHolder2" runat="server">

        </asp:ContentPlaceHolder>


      </div>
   <div id="footer">
        <p>&nbsp;</p> 
   </div>
     </div>


   </div>



</body>
</html>

2 个解决方案

#1


5  

You say that the TreeView and GridView functionality "stops working" when the <form runat="server"> is in the master page -- but if doing two forms (one in the master, one in the page using the master) doesn't work, then technically it's not working either way.

你说当

在母版页中时,TreeView和GridView功能“停止工作” - 但是如果做两个表单(一个在master中,一个在页面中使用master)就不会工作,然后从技术上讲,它无论如何都无法正常工作。

The correct idiom for ASP.NET 2.0+ using master pages is to place the form tag in the master page. The pages using the master, if wired up correctly, will not need form tags -- they will get the tag from their master. The web app I just deployed this morning worked that way. :)

使用母版页的ASP.NET 2.0+的正确习惯是将表单标记放在母版页中。如果正确连接,使用主页的页面将不需要表单标签 - 它们将从主服务器获取标签。我今天早上刚刚部署的网络应用就是这样做的。 :)

I'm guessing that there's actually a code issue buried in the page itself causing the TreeView and GridView to not function once the form tags are implemented correctly.

我猜测页面本身实际上存在一个代码问题,导致TreeView和GridView在表单标签正确实现后无法运行。

EDIT

To be clear, the master page must have <form runat="server">, all of the other controls & HTML needed, the placeholders, and a closing </form> tag.

为了清楚起见,母版页必须具有

,所需的所有其他控件和HTML,占位符以及结束 标记。

The pages using the master cannot have any <form runat="server"> tags at all, and especially not a closing </form> tag.

使用master的页面根本不能有任何

标签,尤其不是结束 标签。

Done this way, there should be no problems.

这样做,应该没有问题。

#2


1  

Your master page should contain the form element, with the closing element at the bottom of it.

您的母版页应包含表单元素,其底部是结束元素。

<%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="MasterPage" %>

<!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>
<title>SumooH</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<form id="form1" runat="server">
    <div>
        <asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server" />
    </div>
    <div>
        <asp:ContentPlaceHolder id="ContentPlaceHolder2" runat="server" />
    </div>
</form>
</body>

Your content pages should not contain any form elements for your purposes.

您的内容页面不应包含任何表单元素。

#1


5  

You say that the TreeView and GridView functionality "stops working" when the <form runat="server"> is in the master page -- but if doing two forms (one in the master, one in the page using the master) doesn't work, then technically it's not working either way.

你说当

在母版页中时,TreeView和GridView功能“停止工作” - 但是如果做两个表单(一个在master中,一个在页面中使用master)就不会工作,然后从技术上讲,它无论如何都无法正常工作。

The correct idiom for ASP.NET 2.0+ using master pages is to place the form tag in the master page. The pages using the master, if wired up correctly, will not need form tags -- they will get the tag from their master. The web app I just deployed this morning worked that way. :)

使用母版页的ASP.NET 2.0+的正确习惯是将表单标记放在母版页中。如果正确连接,使用主页的页面将不需要表单标签 - 它们将从主服务器获取标签。我今天早上刚刚部署的网络应用就是这样做的。 :)

I'm guessing that there's actually a code issue buried in the page itself causing the TreeView and GridView to not function once the form tags are implemented correctly.

我猜测页面本身实际上存在一个代码问题,导致TreeView和GridView在表单标签正确实现后无法运行。

EDIT

To be clear, the master page must have <form runat="server">, all of the other controls & HTML needed, the placeholders, and a closing </form> tag.

为了清楚起见,母版页必须具有

,所需的所有其他控件和HTML,占位符以及结束 标记。

The pages using the master cannot have any <form runat="server"> tags at all, and especially not a closing </form> tag.

使用master的页面根本不能有任何

标签,尤其不是结束 标签。

Done this way, there should be no problems.

这样做,应该没有问题。

#2


1  

Your master page should contain the form element, with the closing element at the bottom of it.

您的母版页应包含表单元素,其底部是结束元素。

<%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="MasterPage" %>

<!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>
<title>SumooH</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<form id="form1" runat="server">
    <div>
        <asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server" />
    </div>
    <div>
        <asp:ContentPlaceHolder id="ContentPlaceHolder2" runat="server" />
    </div>
</form>
</body>

Your content pages should not contain any form elements for your purposes.

您的内容页面不应包含任何表单元素。