1: public partial class AsyncForm : System.Web.UI.Page {
2:
3: private EventHandler ehRecuperarDatosDeGrillaPrincipal = null;
4: private EventHandler ehRecuperarDatosDeDropDownList = null;
5: private RecuperarDatosDeGrillaSecundariaEventHandler ehRecuperarDatosDeGrillaSecundaria = null;
6:
7: private DataSet dsGrillaPrincipal;
8: private DataSet dsDropDownList;
9:
10: protected void Page_Load(object sender, EventArgs e) {
11:
12: // Creamos 2 tareas
13: PageAsyncTask pat1 = new PageAsyncTask(new BeginEventHandler(this.RecuperarDatosDeGrillaPrincipal), new EndEventHandler(this.CargarGrillaPrincipal), null, null, true);
14: PageAsyncTask pat2 = new PageAsyncTask(new BeginEventHandler(this.RecuperarDatosDeDropDownList), new EndEventHandler(this.CargarDropDownList), null, null, true);
15:
16: // Registramos las 2 tareas para que se ejecuten asincronicamente
17: Page.RegisterAsyncTask(pat1);
18: Page.RegisterAsyncTask(pat2);
19: }
20:
21: IAsyncResult RecuperarDatosDeGrillaPrincipal(object sender, EventArgs e, AsyncCallback cb, object state) {
22: this.ehRecuperarDatosDeGrillaPrincipal = new EventHandler(this.RecuperarSetDeDatos1);
23: return this.ehRecuperarDatosDeGrillaPrincipal.BeginInvoke(this, EventArgs.Empty, cb, null);
24: }
25:
26: void CargarGrillaPrincipal(IAsyncResult ar) {
27: this.ehRecuperarDatosDeGrillaPrincipal.EndInvoke(ar);
28: this.GridView1.DataSource = this.dsGrillaPrincipal;
29: this.GridView1.DataBind();
30: }
31:
32: IAsyncResult RecuperarDatosDeDropDownList(object sender, EventArgs e, AsyncCallback cb, object state) {
33: this.ehRecuperarDatosDeDropDownList = new EventHandler(this.RecuperarSetDeDatos2);
34: return this.ehRecuperarDatosDeDropDownList.BeginInvoke(this, EventArgs.Empty, cb, null);
35: }
36:
37: void CargarDropDownList(IAsyncResult ar) {
38: this.ehRecuperarDatosDeDropDownList.EndInvoke(ar);
39: this.DropDownList1.DataSource = this.dsDropDownList;
40: this.DropDownList1.DataBind();
41:
42: this.DropDownList1.SelectedIndex = 0;
43:
44: string id = this.DropDownList1.Items[0].Value;
45: // Cargamos la tarea y le pasamos el ID como parámetro
46: PageAsyncTask pat3 = new PageAsyncTask(new BeginEventHandler(this.RecuperarDatosDeGrillaSecundaria),
47: new EndEventHandler(this.CargarGrillaSecundaria), null, id, true);
48:
49: Page.RegisterAsyncTask(pat3);
50: }
51:
52: IAsyncResult RecuperarDatosDeGrillaSecundaria(object sender, EventArgs e, AsyncCallback cb, object state) {
53: this.ehRecuperarDatosDeGrillaSecundaria = new RecuperarDatosDeGrillaSecundariaEventHandler(this.RecuperarSetDeDatos3);
54: return this.ehRecuperarDatosDeGrillaSecundaria.BeginInvoke((string)state, cb, null);
55: }
56:
57: void CargarGrillaSecundaria(IAsyncResult ar) {
58: // El uso de un EventHandler personalizado nos permite devolver el DataSet
59: DataSet ds = this.ehRecuperarDatosDeGrillaSecundaria.EndInvoke(ar);
60: this.GridView2.DataSource = ds;
61: this.GridView2.DataBind();
62: }
63:
64: private void RecuperarSetDeDatos1(object sender, EventArgs e) {
65: DataSet ds = new DataSet();
66: /*...*/
67: this.dsGrillaPrincipal = ds;
68: }
69:
70: private void RecuperarSetDeDatos2(object sender, EventArgs e) {
71: DataSet ds = new DataSet();
72: /*...*/
73: this.dsDropDownList = ds;
74: }
75:
76: private DataSet RecuperarSetDeDatos3(string id) {
77: DataSet ds = new DataSet();
78: /*...*/
79: return ds;
80: }
81: }