therock
therock

Reputation: 31

DotNetNuke - Events on dynamically loaded subcontrols not firing

Im creating a site walk through module that will dynamically load different controls on different pages. For some reason events on subcontrols are not firing.

Main view

<%@ Control language="C#" Inherits="DotNetNuke.Modules.SiteWalkthrough.View" AutoEventWireup="false"  Codebehind="View.ascx.cs" %>
<%@ Register Src="/DesktopModules/SiteWalkthrough/Controls/Start.ascx" TagPrefix="sw" TagName="start" %>

<asp:MultiView ID="MultiView" runat="server">
    <asp:View ID="mvStart" runat="server">
        <sw:start ID="ucStart" runat="server"></sw:start>
    </asp:View>
</asp:MultiView>

Main view code-behind

namespace DotNetNuke.Modules.SiteWalkthrough
{
    public partial class View : SiteWalkthroughModuleBase, IActionable
    {
        override protected void OnInit(EventArgs e)
        {
            InitializeComponent();
            base.OnInit(e);
        }

        private void InitializeComponent()
        {
            this.Load += new System.EventHandler(this.Page_Load);
        }

        private void Page_Load(object sender, System.EventArgs e)
        {
            MultiView.SetActiveView(mvStart);
        }
    }
}

User control

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Start.ascx.cs" Inherits="DotNetNuke.Modules.SiteWalkthrough.Controls.Start" %>

<div>
    <span>Welcome!</span>
    <span><asp:Button ID="btnNext" runat="server" Text="Okay" CssClass="btnNext" OnClick="btnNext_Click" /></span>
</div>

User control code-behind

namespace DotNetNuke.Modules.SiteWalkthrough.Controls
{
    public partial class Start : PortalModuleBase
    {
        protected void Page_Load(object sender, EventArgs e) {}

        protected void btnNext_Click(object sender, EventArgs e) 
        {
            // this event never fires
        }
    }
}

This code works fine with standard ASP.NET project but not in DotNetNuke. Do I have to manually register events in OnInit on main view?

Upvotes: 3

Views: 1244

Answers (1)

Bruce Chapman
Bruce Chapman

Reputation: 1237

I'm taking a stab here, but my guess would be that you need to bind the control and the event in the _init rather than the _load of the control. This has to do with the page lifecycle.

I would switch off the 'AutoEventWireup' in the control and explicitly code all your event bindings manually.

Upvotes: 1

Related Questions