C
CMELLO
I have am dynamically loading a web user control based on the click of
a tab strip
I load the default control for the first tab in the page load event
after checking page is not postback. After that the controls are
loaded/unloaded based on the SelectionChanged event for the tab strip
and again in Page load because with a dynamic load viewstate has to be
reloaded. I have a datalist in the user control and I am trying to
create the delegate so the parent can handle the click of the edit
button in the user control. Honestly I am not very good at event
delegation the code complies but I never get the command to execute on
the parent
in the child control site.ascx I set up the datalist public event
with code below
public partial class Site : System.Web.UI.UserControl
{
public delegate void myItemCommand(object source,
DataListCommandEventArgs e);
public event myItemCommand dlSiteItemCommand;
override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}
private void InitializeComponent()
{ }
protected void dlSite_ItemCommand(object source,
DataListCommandEventArgs e)
{
if (dlSiteItemCommand != null)
dlSiteItemCommand(source, e);
}
protected void Page_Load(object sender, EventArgs e)
{ //get the data and fill the datalist }
in the parent (Detail) I try to bind to the event in the Site.ascx
When the page loads in the parent the procedure LoadUserControl()
is called and in it after I dynamically load the correct control, I
caste the generic control to an instance of Site so I can see the
public event I created. Thats where I have got it wrong I am SOOOOO
confused. The binding does not work when I click the edit button in
the child datalist I never break into the event that is bound on the
parent Below is parent code. Please I not this is too long an
explanation but I have been trying and reading a long time.
Cindy
public partial class Detail : System.Web.UI.Page
{
private string LastLoadedControl
{
get
{
return ViewState["LastLoaded"] as string;
}
set
{
ViewState["LastLoaded"] = value;
}
}
private void LoadUserControl()
{
string controlPath = LastLoadedControl;
if (!string.IsNullOrEmpty(controlPath))
{
PlaceHolder1.Controls.Clear();
UserControl uc = (UserControl)LoadControl(controlPath);
if (controlPath == "Site.ascx")
{
Site ucSite = (Site)uc;
ucSite.dlSiteItemCommand += new
Site.myItemCommand(ucSite_dlSiteItemCommand);
}
PlaceHolder1.Controls.Add(uc);
}
}
void ucSite_dlSiteItemCommand(object source,
DataListCommandEventArgs e)
{
(source as DataList).EditItemIndex = e.Item.ItemIndex;
(source as DataList).DataSource = dsTunnel;
(source as DataList).DataBind();
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}
private void InitializeComponent()
{}
protected void Page_Load(object sender, EventArgs e)
{
if(!(Page.IsPostBack))
{
string controlPath = null;
controlPath = "Site.ascx";
LastLoadedControl = controlPath;
LoadUserControl();
}
LoadUserControl();
}
private void ts_SelectionChanged(object sender,
JQD.TabStrip.SelectionChangedEventArgs e)
{
int TabPos = e.TabPosition;
ActiveTab = TabPos;
string controlPath = string.Empty;
switch (TabPos)
{
case 0:
controlPath = "Site.ascx";
LastLoadedControl = controlPath;
LoadUserControl();
break;
case 1:
break;
}
a tab strip
I load the default control for the first tab in the page load event
after checking page is not postback. After that the controls are
loaded/unloaded based on the SelectionChanged event for the tab strip
and again in Page load because with a dynamic load viewstate has to be
reloaded. I have a datalist in the user control and I am trying to
create the delegate so the parent can handle the click of the edit
button in the user control. Honestly I am not very good at event
delegation the code complies but I never get the command to execute on
the parent
in the child control site.ascx I set up the datalist public event
with code below
public partial class Site : System.Web.UI.UserControl
{
public delegate void myItemCommand(object source,
DataListCommandEventArgs e);
public event myItemCommand dlSiteItemCommand;
override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}
private void InitializeComponent()
{ }
protected void dlSite_ItemCommand(object source,
DataListCommandEventArgs e)
{
if (dlSiteItemCommand != null)
dlSiteItemCommand(source, e);
}
protected void Page_Load(object sender, EventArgs e)
{ //get the data and fill the datalist }
in the parent (Detail) I try to bind to the event in the Site.ascx
When the page loads in the parent the procedure LoadUserControl()
is called and in it after I dynamically load the correct control, I
caste the generic control to an instance of Site so I can see the
public event I created. Thats where I have got it wrong I am SOOOOO
confused. The binding does not work when I click the edit button in
the child datalist I never break into the event that is bound on the
parent Below is parent code. Please I not this is too long an
explanation but I have been trying and reading a long time.
Cindy
public partial class Detail : System.Web.UI.Page
{
private string LastLoadedControl
{
get
{
return ViewState["LastLoaded"] as string;
}
set
{
ViewState["LastLoaded"] = value;
}
}
private void LoadUserControl()
{
string controlPath = LastLoadedControl;
if (!string.IsNullOrEmpty(controlPath))
{
PlaceHolder1.Controls.Clear();
UserControl uc = (UserControl)LoadControl(controlPath);
if (controlPath == "Site.ascx")
{
Site ucSite = (Site)uc;
ucSite.dlSiteItemCommand += new
Site.myItemCommand(ucSite_dlSiteItemCommand);
}
PlaceHolder1.Controls.Add(uc);
}
}
void ucSite_dlSiteItemCommand(object source,
DataListCommandEventArgs e)
{
(source as DataList).EditItemIndex = e.Item.ItemIndex;
(source as DataList).DataSource = dsTunnel;
(source as DataList).DataBind();
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}
private void InitializeComponent()
{}
protected void Page_Load(object sender, EventArgs e)
{
if(!(Page.IsPostBack))
{
string controlPath = null;
controlPath = "Site.ascx";
LastLoadedControl = controlPath;
LoadUserControl();
}
LoadUserControl();
}
private void ts_SelectionChanged(object sender,
JQD.TabStrip.SelectionChangedEventArgs e)
{
int TabPos = e.TabPosition;
ActiveTab = TabPos;
string controlPath = string.Empty;
switch (TabPos)
{
case 0:
controlPath = "Site.ascx";
LastLoadedControl = controlPath;
LoadUserControl();
break;
case 1:
break;
}