Control within another control in asp.net disables server-side events?
<p>I have a control which has a button on it.  All the button does is redirect the user to another page.  On this control I have another control which just display some stuff, nothing fancy.  When I click on the button, it does nothing.  When I remove or comment out the other control, the button event works.  Is this by design? I am not sure how to fix it or what is causing it.</p>

<p>ControlA.ascx contains a button with an event like so:</p>

<pre><code>protected void Button1_Click(object sender, EventArgs e)
{
    Response.Redirect("~/Home.aspx");
}
</code></pre>

<p>ControlA.ascx contains another control inside of it, lets call it ControlB.ascx.</p>

<p>The Button1 click event does not fire when ControlB.ascx is in ControlA.ascx, but when I remove it or take it out, Button1 event fires and it goes to Home.aspx.  This does not only happen for Button1, if I decide to add a second button and create an event for it, if ControlB is in ControlA, the second button event won't fire either.</p>

<p>ControlA.asx markup and code:</p>

<pre><code>&lt;div&gt;
    &lt;asp:Button runat="server" ID="Button1" Text="Register 2" 
                           onclick="Button1_Click" /&gt;
&lt;/div&gt;
&lt;div&gt;
    &lt;uc:ControlB ID="ControlB" runat="server" /&gt;
&lt;/div&gt;

protected void Button1_Click(object sender, EventArgs e)
{
    Response.Redirect("~/Home.aspx");
}
</code></pre>

<p>ControlB.ascx markup:</p>

<pre><code>&lt;div&gt;
  &lt;p&gt;I am control B&lt;/p&gt;
  &lt;p&gt;
     &lt;sbi:SexyLinkButton ID="SexyLinkButton1" runat="server" Text="Go Home" 
                         PostBackUrl="~/home.aspx" /&gt;

      &lt;asp:Button runat="server" ID="Button1" Text="Register 2" 
                           onclick="Button1_Click" /&gt;

&lt;/p&gt;
&lt;/div&gt;
</code></pre>

<p>As stated before, Button1_Click does not fire if ControlB is inside ControlA, but if I remove ControlB or comment  it out, Button1_Click fires.</p>

<p>I figured something out:</p>

<p>ControlB.ascx had a button on it called SexyButton ( didn't create this, someone else did, lol) and when I removed that from ControlB, ControlA's button worked.  I put an asp.net Button in controlB and it worked, so it has something to do with the SexyButton control.</p>

<p>If I put an asp.net button on ControB along with the SexyLinkButton, the event for Button1 on ControlB does not work.</p>

<p>SexyLinkButton.cs -  If I put the PostBackUrl on the SexyLinkButton, asp.net button events don't fire.  Here is the code the SexyLinkButton.cs:</p>

<pre><code>public class SexyLinkButton : LinkButton
{
    private List&lt;string&gt; Css = new List&lt;string&gt; ();

    public string IconCssClass { get; set; }
    public SizeEnum Size { get; set; }

    public SexyLinkButton()
    {
        Size = SizeEnum.Normal;
    }

    protected override void Render(System.Web.UI.HtmlTextWriter writer)
    {
        if (!string.IsNullOrEmpty(CssClass)) Css.Add(CssClass);             // User added Css
        Css.Add("sbi-button");                                              // Standard Css for button
        if (Size != SizeEnum.Normal) Css.Add(Size.ToString().ToLower());    // Size Css

        // Nested spans per design and css requirements
        HtmlGenericControl span1 = new HtmlGenericControl("span");
        HtmlGenericControl span2 = new HtmlGenericControl("span");

        // Nested span only for icon
        if (!string.IsNullOrEmpty(this.IconCssClass))
        {
            HtmlGenericControl btnspan = new HtmlGenericControl("span");
            btnspan.Attributes.Add("class", IconCssClass.Replace(".", string.Empty));
            btnspan.InnerHtml = this.Text;
            span2.Controls.Add(btnspan);
        }
        else
        {
            span2.InnerHtml = this.Text;
        }

        CssClass = string.Join(" ",Css.ToArray());
        this.Text = "";
        span1.Controls.Add(span2);
        this.Controls.Add(span1);

        base.Render(writer);
    }

    public enum SizeEnum
    {
        Normal,
        Medium,
        Large
    }
}
</code></pre>
