views:

917

answers:

2

I have a master page with two ContentPlaceHolders.

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

In the default page one ContentHolder has a TreeView and the other has a 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.....

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"&gt;

<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<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>
+5  A: 

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.

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. :)

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.

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.

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

Done this way, there should be no problems.

John Rudy
no... if i run then seperately they work perfect.. so the code is fine..
i have posted the .aspx page if u want i can post the masterpage too, if that helps in anyway... thanks
i tried that but as i told you the treeview control and the gridviewcontrol functionality stops working..... This why i am confused as to what to do...
But only the gridview? The treeview works? I think you still have a `</form>` in the page somewhere if that's the case. Please edit your post to show the code you're changing it to, where form is in the master and there are no form tags in the child ... Then we can troubleshoot more effectively.
John Rudy
+1  A: 

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"&gt;

<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<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.

Aaron Daniels
I did the same thing first, but when i do this the gridview and treeview functionality stops working. why does that happen... and when i put the form in masterpage i remove the form from all other pages...
I think you may have something else going on then.
Aaron Daniels