Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Dynamic loaded control event delegate does not fire on server

Reply
Thread Tools

Dynamic loaded control event delegate does not fire on server

 
 
cindy
Guest
Posts: n/a
 
      09-08-2008
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;
}

icndy
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
dynamic loaded ascx delegate event not firing in parent form CMELLO@tams.com ASP .Net Building Controls 1 09-12-2008 06:20 PM
dynamic loaded datalist ascx event delegate not firing in parent f cindy ASP .Net 0 09-09-2008 04:16 PM
Event fails to fire first time in dynamically loaded user control( =?Utf-8?B?U3RldmUgQm9vdGg=?= ASP .Net 6 04-06-2005 07:53 PM
How does Page_Load fire when control loaded with LoadControl?? just_jt ASP .Net Web Controls 1 08-25-2004 09:21 PM
user control in a datagrid does not work with a delegate and event David Cho ASP .Net Datagrid Control 0 10-09-2003 11:18 PM



Advertisments