 |
| ASP.NET 1.x and 2.0 Application Design Application design with ASP.NET 1.0, 1.1, and 2.0. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ASP.NET 1.x and 2.0 Application Design section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

March 15th, 2005, 02:40 PM
|
|
Authorized User
|
|
Join Date: Dec 2004
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Sending a web form as parameter
Hello:
From a web form Iâm sending to execute a function contained into a class, code in web form is:
bool que = WUC_CreDes.Class1.Hay_PostBack(this, w1,w1cx, w1ID, w2, w2cx, w2ID);
In class code is:
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;
}
As you can see, Iâm sending to function container into class my WebForm1 to create in function WUC dynamically created.
Thinking in a second web form, let us say, WebForm2, if within it I send to execute my function:
bool que = WUC_CreDes.Class1.Hay_PostBack(this, w1,w1cx, w1ID, w2, w2cx, w2ID);
How can I do to function Hay_PostBack, above mentioned work also for WebForm2 What I need to change because first parameter is WUC_CreDes.Web Form1 parent1?
Iâll thank your answers.
Greetings.
A.L.
El Hombre que tiene Amigos ha de mostrarse Amigo
__________________
El Hombre que tiene Amigos ha de mostrarse Amigo
|
|

March 17th, 2005, 04:25 PM
|
|
Friend of Wrox
|
|
Join Date: Jul 2004
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
|
|
I think you need to pass a more general object,an object WUC_CreDes.WebForm1 and WUC_CreDes.WebForm2 are derived from like Page,
public static bool Hay_PostBack(System.Web.UI.Page page,....){}
_____________
Mehdi.
software student.
|
|

March 17th, 2005, 08:04 PM
|
|
Authorized User
|
|
Join Date: Dec 2004
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I'm coding:
public static bool Hay_PostBack(System.Web.UI.Page parent1, string w1,
string w1cx,
string w1ID,
string w2,
string w2cx,
string w2ID)
{
string fofoi = parent1.GetType().ToString();
if(fofoi == "ASP.WebForm1_aspx")
{
WUC_CreDes.WebForm1 frm = (WUC_CreDes.WebForm1) parent1;
}
else
{
if(fofoi == "ASP.WebForm2_aspx")
{
WUC_CreDes.WebForm2 frm = (WUC_CreDes.WebForm2) parent1;
}
}
But frm is not being recogniz by system
In what am I wrong???
El Hombre que tiene Amigos ha de mostrarse Amigo
|
|

March 18th, 2005, 10:35 AM
|
|
Friend of Wrox
|
|
Join Date: Jul 2004
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
|
|
you declared frm in {} so it's just recognized within {},
Code:
WUC_CreDes.WebForm1 frm1;
WUC_CreDes.WebForm2 frm2;
if(parent1 is WUC_CreDes.WebForm1)
{
frm1 = (WUC_CreDes.WebForm1) parent1;
}
else
{
if(parent1 is WUC_CreDes.WebForm2)
{
frm2 = (WUC_CreDes.WebForm2) parent1;
}
}
_____________
Mehdi.
software student.
|
|

March 18th, 2005, 07:20 PM
|
|
Authorized User
|
|
Join Date: Dec 2004
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks you Mehdi:
But still I've an error.
My code is now:
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();
}
}
When I compile, in line: frm1.parent1.Example.Controls.Clear();
is sending me this error:
'WUC_CreDes.WebForm1' haven't a deffinition to 'parent1' Why?
I'll thank your help
A.L.
El Hombre que tiene Amigos ha de mostrarse Amigo
|
|

March 19th, 2005, 04:38 AM
|
|
Friend of Wrox
|
|
Join Date: Jul 2004
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
|
|
because : 'WUC_CreDes.WebForm1' haven't a deffinition to 'parent1'
try,
frm1.Example.Controls.Clear();
_____________
Mehdi.
software student.
|
|

March 22nd, 2005, 12:56 PM
|
|
Authorized User
|
|
Join Date: Dec 2004
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I'm sorry Mehdi, but still doing as you told me error persist.
Example is a place holder contening both in WebForm1 and in WebForm2.
Iâll thank your help.
El Hombre que tiene Amigos ha de mostrarse Amigo
|
|

March 22nd, 2005, 07:07 PM
|
|
Authorized User
|
|
Join Date: Dec 2004
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Finally I found the solution:
To call function:
bool que = WUC_CreDes.Class1.Hay_PostBack(this, w1,w1cx, w1ID, w2, w2cx, w2ID);
The 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;
}
Greetings.
A.L.
El Hombre que tiene Amigos ha de mostrarse Amigo
|
|
 |