Dynamically Loading user control

B

Beegee

Hi
Happy 2006

I want to load the user control dynamically. I want to change to different
usercontrol page to the same place holder accordingly.

If there is no way to do so anyone please suggest me how to evaluate a
string of expression.
I have used the same in VBscript and javascript.
e.g.

stringvariable1 = "TemplateTopUserControl";
stringvariable2 = "\"TemplateTop.ascx\"";

"this." + stringvariable1 + " = (" + stringvariable1 + ")this.LoadControl("
+ stringvariable2 +")"

I want this to be executed as

this.TemplateTopUserControl = (TemplateTopUserControl)
this.LoadControl("TemplateTop.ascx");

I know that we can use eval function available in javascript so I want to
know the equivalent in C#.


Thanks very much

BG
 
G

Guest

Beegee,
..NET does not have the equivalent of an "eval" keyword as it is a compiled,
not an interpreted language / runtime.

If you want to provide something similar to scripting capabilities in your
app, you can compile your code on the fly into an in-memory assembly.

Another option would be to use either an interface, or a static Hashtable of
the keys / names of the controls to load, and have a switch or a set of if
-else statements to determine what to pass to the LoadControl method.
Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,479
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top