title: Handle Multiple Form tag in asp.net page?
body: <p>My page contains a user control and inherits a master page.  Both have a button.  I have put it in a form tag.  I am just trying to do an event bubbling from master page as well as user control. Now it doesn't load because of multiple form tags error. How to do it?</p>
  
  <p><strong>Masterpage :</strong> </p>
  
  <pre><code>&lt;%@ Master Language="C#" AutoEventWireup="True" CodeBehind="SampleSite.master.cs" Inherits="EventBubbling.SampleSite" %&gt;
  
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  
  &lt;html xmlns="http://www.w3.org/1999/xhtml" &gt;
  &lt;head&gt;
      &lt;title&gt;&lt;/title&gt;
      &lt;asp:ContentPlaceHolder ID="head" runat="server"&gt;
      &lt;/asp:ContentPlaceHolder&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;form id="form1" runat="server"&gt;
      &lt;div&gt;
          &lt;asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server"&gt;
              &lt;asp:Button ID="Button1" runat="server" Text="MasterPageButton" /&gt;
          &lt;/asp:ContentPlaceHolder&gt;
      &lt;/div&gt;
      &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>User control :</strong> </p>
  
  <pre><code>&lt;%@ Control Language="C#" AutoEventWireup="True" CodeBehind="SampleUserControl.ascx.cs"
      Inherits="EventBubbling.Controls.SampleUserControl" EnableViewState="false" %&gt;
  
   &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  
  &lt;html xmlns="http://www.w3.org/1999/xhtml" &gt;
  &lt;head id="Head1" runat="server"&gt;
      &lt;title&gt;&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;form id="form1" runat="server"&gt;
      &lt;div&gt;
      &lt;asp:Button ID="btnUC" runat="server" OnClick="btnUC_Click" Text="UserControlButton" /&gt;
      &lt;/div&gt;
      &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>User control.cs page :</strong></p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  using System.Web.UI;
  using System.Web.UI.WebControls;
  
  namespace EventBubbling.Controls
  {
      public partial class SampleUserControl : System.Web.UI.UserControl
      {
          public event EventHandler buttonClick;
          protected void Page_Load(object sender, EventArgs e)
          {
  
          }
  
          protected void btnUC_Click(object sender, EventArgs e)
          {
              buttonClick(sender, e);
          }
      }
  }
  </code></pre>
  
  <p><strong>Main Page :</strong> </p>
  
  <pre><code>&lt;%@ Page Language="C#" AutoEventWireup="True" MasterPageFile="~/SampleSite.Master"
      CodeBehind="Default.aspx.cs" Inherits="EventBubbling._Default" %&gt;
  
  &lt;%@ Register Src="~/Controls/SampleUserControl.ascx" TagPrefix="uc" TagName="SampleUserControl" %&gt;
  &lt;asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server"&gt;
      &lt;div&gt;
          &lt;uc:SampleUserControl ID="UC1" runat="server" /&gt;
      &lt;/div&gt;
  &lt;/asp:Content&gt;
  </code></pre>
  
  <p><strong>.cs</strong></p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  using System.Web.UI;
  using System.Web.UI.WebControls;
  
  namespace EventBubbling
  {
      public partial class _Default : System.Web.UI.Page
      {
          Button btn = new Button();
  
          protected void Page_Load(object sender, EventArgs e)
          {
              UC1.buttonClick += new EventHandler(UC1_buttonClick);
              btn = this.Master.FindControl("Button1") as Button;
              btn.Click += new EventHandler(btn_Click);
  
          }
  
          void btn_Click(object sender, EventArgs e)
          {
              Response.Write("EventBubbling from MasterPage");
          }
  
          void UC1_buttonClick(object sender, EventArgs e)
          {
              Response.Write("EventBubbling from User control");
          }
  
      }
  }
  </code></pre>
  
  <p>My goal is to learn event bubbling but I get some basic error with this code I posted.</p>