About the Load Control Method

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

Guest

Hi,

Normally i use the LoadControl method following this way:
LoadControl("usercontrol1.ascx");

But its possible do something like this.

string control="usercontrol1.ascx";
LoadControl(control);

If not, could you recomend any solution to resolve my problem?
 
Hi,

I see nowhere in the documentation that the parameter should be set at
compiler time

Did you tried it?

cheers,
 
Hi, Ignacio i try to do it, and it works i can do a
LoadControl(variable)...

About the another post that i put in the forum this is my answer:

Hi Ignacio, Mi problem is exactly this (in Web)
I have:
- an aspx page
- an ascx control (Exercise1.ascx)
- an ascx control (Exercise2.ascx)

Inside the aspx page i have a placeholder to add a control dinamically.
This placeholder's name is Exercise.

In the aspx page i have this in the OnInit:

override protected void OnInit(EventArgs e)
{
if(Page.Session["Exercise"]!=null)
{
switch(Page.Session["Exercise"].ToString())
{
case "Exercise2.ascx":
Exercise2 Exercise2_=(Exercise2)LoadControl("Exercise2.ascx");
Exercise.Controls.Add(Exercise2_);
break;
}
}
else
{
Exercise1 Exercise1_=(Exercise1)LoadControl("Exercise1.ascx");
Exercise.Controls.Add(Exercise1_);
}
}

In the (for instance) Exercise1.ascx i have this in the onClick method
of a button:

private void ExerciseBtn_Click(object sender, EventArgs e)
{
//add into the session the next exercise to load
Page.Session.Add("Exercise","Exercise2.ascx");
}

If i click in the button inside the usercontrol twice the program works,
but i would like only to need one click.
Thanks.
Josema.

Thanks.
Kind Regards.
Josema.
 
Back
Top