473,394 Members | 1,703 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Dynamically Loading user control

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

Jan 14 '06 #1
1 1097
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
--
Co-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

Jan 14 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Tim T | last post by:
Hi, I have the need to use dynamically loaded user controls in a webform page. I have the controls loading dynamically, and that part works fine. this is the code used in a webform to dynamically...
1
by: Earl Teigrob | last post by:
PROBLEM: When a user control is loaded into a PlaceHolder control more than once, the events do not fire on the first click of a control on the dynamically loaded user control. In other words, the...
2
by: Eric | last post by:
I'm trying to dynamically load a user control using on the .NET framework (not Visual Studio). The control was designed in Visual Studio and is named: Disable.ascx The first line is: <%@...
1
by: Kamal Jeet Singh | last post by:
Hi Friends !! I am have facing problem in controlling the dynamically created controls on web page. The problem Scenario is Scenario:- My requirement is to load the web user controls on the...
1
by: Kamal Jeet Singh | last post by:
Hi Friends !! I am facing problem in controlling the dynamically created controls on web page. The problem Scenario is Scenario:- My requirement is to load the web user controls on the web...
6
by: Steve Booth | last post by:
I have a web form with a button and a placeholder, the button adds a user control to the placeholder (and removes any existing controls). The user control contains a single button. I have done all...
7
by: Samuel | last post by:
Hi, I am building a page that makes use of user control as a templating technique. The following is that I have in mind and it is actually working: Root/ -- login.aspx -- login.aspx.vb --...
2
by: A.Wussow | last post by:
Hi Everybody, i want to load dynamically content from some user controls (with forms, or some data-controls) using atlas. So i use an UpdatePanel for loading the user control into a placeholder....
1
by: Bob Rock | last post by:
Hello, I'm new to ASP.NET and I've been looking into the topic of dynamically loading (typically accomplished with a LoadControl followed by a MyControl.Controls.Add()) both user controls and...
5
by: Andrew Robinson | last post by:
I have a page that can load a number of different user controls. Each of these user controls inherits from a common base class and the controls are loaded based on application state, status, etc...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.