Foros del Web » Programación para mayores de 30 ;) » .NET »

Pasando una web form como parametro

Estas en el tema de Pasando una web form como parametro en el foro de .NET en Foros del Web. Hola: A partir de una web form estoy enviando a ejecutar una función contenida en una clase, el código en la web form es: bool ...
  #1 (permalink)  
Antiguo 15/03/2005, 12:17
Avatar de see07  
Fecha de Ingreso: abril-2004
Ubicación: México, D.F.
Mensajes: 112
Antigüedad: 20 años
Puntos: 0
Pasando una web form como parametro

Hola:
A partir de una web form estoy enviando a ejecutar una función contenida en una clase, el código en la web form es:

bool que = WUC_CreDes.Class1.Hay_PostBack(this, w1,w1cx, w1ID, w2, w2cx, w2ID);

En la clase es código es:

public static bool Hay_PostBack(WUC_CreDes.WebForm1 parent1, string w1,
string w1cx,
string w1ID,
string w2,
string w2cx,
string w2ID)
{
string cual = "";
cual = HttpContext.Current.Session["par1"].ToString();
parent1.Example.Controls.Clear();
if(cual == w1)
{
Control control = parent1.Page.LoadControl(w1cx);
control.ID = w1ID;
parent1.Example.Controls.Add(control);
}
else
{
Control control = parent1.Page.LoadControl(w2cx);
control.ID = w2ID;
parent1.Example.Controls.Add(control);
}
return false;
}

Como ven estoy pasando a la función contenida en la clase la WebForm1 para crear en ella WUC dinámicamente.

Pensando en una segunda web form, digamos WebForm2, si desde allí envío a ejecutar la función:

bool que = WUC_CreDes.Class1.Hay_PostBack(this, w1,w1cx, w1ID, w2, w2cx, w2ID);

¿Cómo puedo hacer para que la función Hay_PostBack arriba mencionada funcione también para la WebForm2? ¿Qué cambio habría que hacerle ya que el primer parámetro es WUC_CreDes.Web Form1 parent1?

Les agradeceré sus repuestas.

Saludos.

A.L.
__________________
El hombre que tiene amigos ha de mostrarse amigo....
  #2 (permalink)  
Antiguo 22/03/2005, 09:17
Avatar de see07  
Fecha de Ingreso: abril-2004
Ubicación: México, D.F.
Mensajes: 112
Antigüedad: 20 años
Puntos: 0
He seguido trabajando con el código, ahora estoy aquí:

public static bool Hay_PostBack(System.Web.UI.Page parent1, string w1,
string w1cx,
string w1ID,
string w2,
string w2cx,
string w2ID)
{
WUC_CreDes.WebForm1 frm1;
WUC_CreDes.WebForm2 frm2;

string fofoi = parent1.GetType().ToString();
if(fofoi == "ASP.WebForm1_aspx")
{
frm1 = (WUC_CreDes.WebForm1) parent1;
frm1.parent1.Example.Controls.Clear();
}
}

Sin embargo en la última línea: frm1.parent1.Example.Controls.Clear();
Me da el error: 'WUC_CreDes.WebForm1' no contiene una definición paera 'parent1'.

Example es un place holder contenido tanto en WebForm1 como en WebForm2.

Agradeceré vuestra ayuda.

A.L.
__________________
El hombre que tiene amigos ha de mostrarse amigo....
  #3 (permalink)  
Antiguo 22/03/2005, 16:35
Avatar de see07  
Fecha de Ingreso: abril-2004
Ubicación: México, D.F.
Mensajes: 112
Antigüedad: 20 años
Puntos: 0
Finalmente encontré la solución:

Para llamar la function:

bool que = WUC_CreDes.Class1.Hay_PostBack(this, w1,w1cx, w1ID, w2, w2cx, w2ID);

La function:

public static bool Hay_PostBack(System.Web.UI.Page parent1, string w1,
string w1cx,
string w1ID,
string w2,
string w2cx,
string w2ID)
{
WUC_CreDes.WebForm1 frm1;
WUC_CreDes.WebForm2 frm2;

string cual = "";
cual = HttpContext.Current.Session["par1"].ToString();

string fofoi = parent1.GetType().ToString();
if(fofoi == "ASP.WebForm1_aspx")
{
frm1 = (WUC_CreDes.WebForm1) parent1;


frm1.Example.Controls.Clear();


if(cual == w1)
{
Control control = frm1.Page.LoadControl(w1cx);
control.ID = w1ID;
frm1.Example.Controls.Add(control);
}
else
{
Control control = frm1.Page.LoadControl(w2cx);
control.ID = w2ID;
frm1.Example.Controls.Add(control);
}
}
else
{
if(fofoi == "ASP.WebForm2_aspx")
{
frm2 = (WUC_CreDes.WebForm2) parent1;
frm2.Example.Controls.Clear();

if(cual == w1)
{
Control control = frm2.Page.LoadControl(w1cx);
control.ID = w1ID;
frm2.Example.Controls.Add(control);
}
else
{
Control control = frm2.Page.LoadControl(w2cx);
control.ID = w2ID;
frm2.Example.Controls.Add(control);
}
}
}
return false;
}

Saludos.

A.L.
__________________
El hombre que tiene amigos ha de mostrarse amigo....
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 22:49.