fadetoblack
Programmer
I'm trying to dynamically load user controls based on click events. But, for some reason
lb_websites in (listed below) header.ascx's click event doesn't register as being invoked.
Default5.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default5.aspx.cs" Inherits="Default5" %>
<%@ Register Src="~\user_controls\blank.ascx" TagName="header" TagPrefix="uc" %>
<%@ Register Src="~\user_controls\blank.ascx" TagName="menu" TagPrefix="uc" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
<html xmlns=" >
<head runat="server">
<title>Untitled Page</title>
<link href="cms.css" rel="stylesheet" type="text/css" />
</head>
<body>
<form id="frame_form" runat="server">
<div id="header_area" class="header_area" runat="server"><uc:header ID="wuc_header" runat="server" /></div>
<div id="main_area" class="main_area" runat="server">
<div id="menu" class="menu" runat="server"><uc:menu ID="wuc_menu" runat="server" /></div>
</div>
</form>
</body>
</html>
Default5.aspx.cs
using System;
using System.Collections;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Default5 : System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e) {
header_area.Controls.Add(LoadControl(@"~/user_controls/header.ascx"));
if (Page.IsPostBack) {
this.wuc_header.clicked += new blank.OnButtonClick(default_click);
this.wuc_menu.clicked += new blank.OnButtonClick(default_click);
}
}
}
void default_click(string button_text) {
// loading controls
}
blank.ascx.cs
using System;
public partial class blank : System.Web.UI.UserControl {
// Delegate declaration
public delegate void OnButtonClick(string button_clicked);
// Event declaration
public event OnButtonClick clicked;
}
header.ascx
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="~/user_controls/header.ascx.cs" Inherits="header" %>
<asp:LinkButton ID="lb_websites" runat="server" Text="websites" OnClick="lb_Click" />
<asp:LinkButton ID="lb_administration" runat="server" Text="administration" OnClick="lb_Click" />
header.ascx.cs
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class header : System.Web.UI.UserControl {
// Delegate declaration
public delegate void OnButtonClick(string button_clicked);
// Event declaration
public event OnButtonClick clicked;
protected void Page_Load(object sender, EventArgs e) { }
protected void lb_Click(object sender, EventArgs e) {
// Check if event is null
if (clicked != null) clicked(((LinkButton)sender).Text);
}
}
lb_websites in (listed below) header.ascx's click event doesn't register as being invoked.
Default5.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default5.aspx.cs" Inherits="Default5" %>
<%@ Register Src="~\user_controls\blank.ascx" TagName="header" TagPrefix="uc" %>
<%@ Register Src="~\user_controls\blank.ascx" TagName="menu" TagPrefix="uc" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
<html xmlns=" >
<head runat="server">
<title>Untitled Page</title>
<link href="cms.css" rel="stylesheet" type="text/css" />
</head>
<body>
<form id="frame_form" runat="server">
<div id="header_area" class="header_area" runat="server"><uc:header ID="wuc_header" runat="server" /></div>
<div id="main_area" class="main_area" runat="server">
<div id="menu" class="menu" runat="server"><uc:menu ID="wuc_menu" runat="server" /></div>
</div>
</form>
</body>
</html>
Default5.aspx.cs
using System;
using System.Collections;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Default5 : System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e) {
header_area.Controls.Add(LoadControl(@"~/user_controls/header.ascx"));
if (Page.IsPostBack) {
this.wuc_header.clicked += new blank.OnButtonClick(default_click);
this.wuc_menu.clicked += new blank.OnButtonClick(default_click);
}
}
}
void default_click(string button_text) {
// loading controls
}
blank.ascx.cs
using System;
public partial class blank : System.Web.UI.UserControl {
// Delegate declaration
public delegate void OnButtonClick(string button_clicked);
// Event declaration
public event OnButtonClick clicked;
}
header.ascx
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="~/user_controls/header.ascx.cs" Inherits="header" %>
<asp:LinkButton ID="lb_websites" runat="server" Text="websites" OnClick="lb_Click" />
<asp:LinkButton ID="lb_administration" runat="server" Text="administration" OnClick="lb_Click" />
header.ascx.cs
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class header : System.Web.UI.UserControl {
// Delegate declaration
public delegate void OnButtonClick(string button_clicked);
// Event declaration
public event OnButtonClick clicked;
protected void Page_Load(object sender, EventArgs e) { }
protected void lb_Click(object sender, EventArgs e) {
// Check if event is null
if (clicked != null) clicked(((LinkButton)sender).Text);
}
}