Events not firing (First time only) in a dynamic user control. Please help.

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I've noticed that none of the child controls events are firing for the first time from the dynamic user control. Here is the event cycle.

1) MainPage_load
2) User control1_Load

user clicks a dropdown in UC1
_________________________

1) MainPage_Load
2) User Control_1 Load
3) dropdown__SelectedIndexChanged in User control1:
sends a 'Report Changed' event to main page.
4) MainPage_ReportChanged : Loads_Report User control
sends a 'Create Report' event to newly loaded control and saves report name in view state.
5) Report_UserControl_Load
6) Report_UserControl: Create Report (Populates a datagrid etc.)

Userclicks a button control on Report User control:
_____________________________________
1) Main Page_Load
2) User Control_1 Load
3) Report User Control Load ( Main page dynamically loads this control by looking at the report name saved in view state)

PROBLEM:< ReportUserControl_Button control event does NOT get fired >

User clicks on button control on Report User Control:
___________________________________________
1) Main Page_Load
2) User Control_1 Load
3) Report User Control Load ( Main page dynamically loads this control by looking at the report name saved in view state)

ReportUserControl_Button control event gets fired


----- Shourie wrote: -----

Hi all,

I'm creating a reporting application, which is primarily a webpage with two user controls. One user control has a drop down with report names and other selection criteria controls needed for the report.
whenever the selection changes in the Report dropdown in the first user control, it sends a custom event to to the main page with the report name,selection criteria as eventargs.
The main page in turn loads the appropriate usercontrol for that report and sends another custom event to that usercontrol to create a report which typically has a datagrid.

So far so good,but when I click on a commandbutton in the datagrid, the ItemCommand fire does not fire for the first time but starts working from the second click.

I can see that binding the datagrid after the 'Report User controls Page_Load' (by way of handling an event from main page ) may be causing the event to not fire. However my requirement is also that I dynamically load the report control first and load its data. Greatly appreciate if any of you can show some direction on how I might be able to solve this design issue.

Thanks,
-Shourie


----- Shourie wrote: -----

Hi all,

I'm creating a reporting application, which is primarily a webpage with two user controls. One user control has a drop down with report names and other selection criteria controls needed for the report.
whenever the selection changes in the Report dropdown in the first user control, it sends a custom event to to the main page with the report name,selection criteria as eventargs.
The main page in turn loads the appropriate usercontrol for that report and sends another custom event to that usercontrol to create a report which typically has a datagrid.

So far so good,but when I click on a commandbutton in the datagrid, the ItemCommand fire does not fire for the first time but starts working from the second click.

I can see that binding the datagrid after the 'Report User controls Page_Load' (by way of handling an event from main page ) may be causing the event to not fire. However my requirement is also that I dynamically load the report control first and load its data. Greatly appreciate if any of you can show some direction on how I might be able to solve this design issue.
 
I found the solution. I need to just set the IDs of the dynamically user controls for the events to fire.
Strange.(I'm even loading the usercontrol in the same function ).
Can any one throw light on why the ID is needed for the dynamic user control ?

Regards,
Shourie

----- Shourie wrote: -----

I've noticed that none of the child controls events are firing for the first time from the dynamic user control. Here is the event cycle.

1) MainPage_load
2) User control1_Load

user clicks a dropdown in UC1
_________________________

1) MainPage_Load
2) User Control_1 Load
3) dropdown__SelectedIndexChanged in User control1:
sends a 'Report Changed' event to main page.
4) MainPage_ReportChanged : Loads_Report User control
sends a 'Create Report' event to newly loaded control and saves report name in view state.
5) Report_UserControl_Load
6) Report_UserControl: Create Report (Populates a datagrid etc.)

Userclicks a button control on Report User control:
_____________________________________
1) Main Page_Load
2) User Control_1 Load
3) Report User Control Load ( Main page dynamically loads this control by looking at the report name saved in view state)

PROBLEM:< ReportUserControl_Button control event does NOT get fired >

User clicks on button control on Report User Control:
___________________________________________
1) Main Page_Load
2) User Control_1 Load
3) Report User Control Load ( Main page dynamically loads this control by looking at the report name saved in view state)

ReportUserControl_Button control event gets fired


----- Shourie wrote: -----

Hi all,

I'm creating a reporting application, which is primarily a webpage with two user controls. One user control has a drop down with report names and other selection criteria controls needed for the report.
whenever the selection changes in the Report dropdown in the first user control, it sends a custom event to to the main page with the report name,selection criteria as eventargs.
The main page in turn loads the appropriate usercontrol for that report and sends another custom event to that usercontrol to create a report which typically has a datagrid.

So far so good,but when I click on a commandbutton in the datagrid, the ItemCommand fire does not fire for the first time but starts working from the second click.

I can see that binding the datagrid after the 'Report User controls Page_Load' (by way of handling an event from main page ) may be causing the event to not fire. However my requirement is also that I dynamically load the report control first and load its data. Greatly appreciate if any of you can show some direction on how I might be able to solve this design issue.

Thanks,
-Shourie


----- Shourie wrote: -----

Hi all,

I'm creating a reporting application, which is primarily a webpage with two user controls. One user control has a drop down with report names and other selection criteria controls needed for the report.
whenever the selection changes in the Report dropdown in the first user control, it sends a custom event to to the main page with the report name,selection criteria as eventargs.
The main page in turn loads the appropriate usercontrol for that report and sends another custom event to that usercontrol to create a report which typically has a datagrid.

So far so good,but when I click on a commandbutton in the datagrid, the ItemCommand fire does not fire for the first time but starts working from the second click.

I can see that binding the datagrid after the 'Report User controls Page_Load' (by way of handling an event from main page ) may be causing the event to not fire. However my requirement is also that I dynamically load the report control first and load its data. Greatly appreciate if any of you can show some direction on how I might be able to solve this design issue.
 
For dynamical loading user controls we must set ID property.With out ID property events will not fire.
private void LoadUserControl()
{
string controlPath = LastLoadedControl;

if (!string.IsNullOrEmpty(controlPath))
{
PlaceHolder1.Controls.Clear();
UserControl uc = (UserControl)LoadControl(controlPath);//loading user control dynamically
uc.ID = "uc";//setting ID Property for user control
PlaceHolder1.Controls.Add(uc);

}
}
 
Back
Top