|
.net
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Dynamically Loading user controlHappy 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 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 -- Show quoteHide quoteCo-founder, Eggheadcafe.com developer portal: http://www.eggheadcafe.com UnBlog: http://petesbloggerama.blogspot.com "Beegee" wrote: > 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 > > > >
Other interesting topics
How to show variable on webpage?
Is this static method threadsafe? ASP.Net prefers Firefox? How to I know the previous page is clicked to forward the current page? Session Authentication Authorization Compiler Error: [No relevant source lines] output cache question PLS HELP: Simple adding data to db in ASP.NET 2.0 How to I know the previous page is clicked to forward the current page? VWD 2005 Express: "copy web site" creates multiple publishform (2.0) |
|||||||||||||||||||||||