473,387 Members | 1,606 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,387 software developers and data experts.

C# eval function?

Is there an "eval" function in C#? Here is what I want to do:

I have a lot of controls like this:

<asp:textbox id="books_quantity" runat="server"/>
<asp:textbox id="vcds_quantity" runat="server"/>
<asp:textbox id="dvds_quantity" runat="server"/>

In my script, I want to refer to the names dynamically like this:

eval("books" + "_quantity").Text = 100;

Is it possible in C#? Because in PHP, Javascript.. they all can do this.

Help..
Nov 15 '05 #1
3 38451
Nope.
C# is compiled language.
Compiler must know up front what object you are accessing.
You can use FindControl(name) and then cast it to Textbox.

George.

"ChAnGePoInT_DaWg" <Su*******@RichMan.Diu> wrote in message
news:E5**********@twister01.bloor.is.net.cable.rog ers.com...
Is there an "eval" function in C#? Here is what I want to do:

I have a lot of controls like this:

<asp:textbox id="books_quantity" runat="server"/>
<asp:textbox id="vcds_quantity" runat="server"/>
<asp:textbox id="dvds_quantity" runat="server"/>

In my script, I want to refer to the names dynamically like this:

eval("books" + "_quantity").Text = 100;

Is it possible in C#? Because in PHP, Javascript.. they all can do this.

Help..

Nov 15 '05 #2
Hi,

You can get the functionality in ASP.NET ( it does not matter if in Vb.net
or C# ) but no using an "eval" feature, .NET languages ( not sure for
jscript ) are compiled languages meaning that you cannot "evaluate" an
expression at runtime. That's a big difference between a compiled language
and a interpreted one.

The feature that let you do that in ASP.NET is cause all the controls in the
page are referenced in a collection, named Controls , now it turns out that
each control has a string property named Name that contain the name of the
control, this is assigned by the page parser when the page is first
compiled.
Therefore to get a reference to a control you can do this:

Controls.Find( "control_name");

This return a Control instance which you must cast it back to the correct
type:

TextBox tb = ( TextBox) Controls.Find( "control_name");
tb.Text = "asdfaf";
Hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"ChAnGePoInT_DaWg" <Su*******@RichMan.Diu> wrote in message
news:E5**********@twister01.bloor.is.net.cable.rog ers.com...
Is there an "eval" function in C#? Here is what I want to do:

I have a lot of controls like this:

<asp:textbox id="books_quantity" runat="server"/>
<asp:textbox id="vcds_quantity" runat="server"/>
<asp:textbox id="dvds_quantity" runat="server"/>

In my script, I want to refer to the names dynamically like this:

eval("books" + "_quantity").Text = 100;

Is it possible in C#? Because in PHP, Javascript.. they all can do this.

Help..

Nov 15 '05 #3
Create an assembly with JScript.net that does this. C# can't do it natively,
unless you use CodeDOM and generate a temporary in-memory assembly that has
the code to execute the code.

--
____________________
Klaus H. Probst, MVP
http://www.vbbox.com/

"ChAnGePoInT_DaWg" <Su*******@RichMan.Diu> wrote in message
news:E5**********@twister01.bloor.is.net.cable.rog ers.com...
Is there an "eval" function in C#? Here is what I want to do:

I have a lot of controls like this:

<asp:textbox id="books_quantity" runat="server"/>
<asp:textbox id="vcds_quantity" runat="server"/>
<asp:textbox id="dvds_quantity" runat="server"/>

In my script, I want to refer to the names dynamically like this:

eval("books" + "_quantity").Text = 100;

Is it possible in C#? Because in PHP, Javascript.. they all can do this.

Help..

Nov 15 '05 #4

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

Similar topics

4
by: Jean-Sébastien Bolduc | last post by:
Hello, I would like to associate a local namespace with a lambda function. To be more specific, here is exactly what I would want: def foo(): a = 1 f = lambda x : a*x return f
9
by: HikksNotAtHome | last post by:
This is a very simplified example of an Intranet application. But, is there an easier (or more efficient) way of getting the decimal equivalent of a fraction? The actual function gets the select...
12
by: knocte | last post by:
Hello. I have always thought that the eval() function was very flexible and useful. If I use it, I can define functions at runtime!! However, I have found a case where eval() does not work...
18
by: Joe Fallon | last post by:
I have some complex logic which is fairly simply to build up into a string. I needed a way to Eval this string and return a Boolean result. This code works fine to achieve that goal. My...
3
by: Pauljh | last post by:
Hi All, I'm running some javascript over a server side generated web page and have multiple generated empty select statements, that I want to populate when the page is loaded. As HTML doesn't do...
7
by: Darko | last post by:
Hello, I have this particular problem with eval() when using Microsoft Internet Explorer, when trying to define an event handler. This is the code: function BigObject() { this.items = new...
6
by: vasudevram | last post by:
Hi group, Question: Do eval() and exec not accept a function definition? (like 'def foo: pass) ? I wrote a function to generate other functions using something like eval("def foo: ....") but...
2
by: Florian Loitsch | last post by:
hi, What should be the output of the following code-snippet? === var x = "global"; function f() { var x = 0; eval("function x() { return false; }"); delete x; alert(x); }
6
by: RandomElle | last post by:
Hi there I'm hoping someone can help me out with the use of the Eval function. I am using Access2003 under WinXP Pro. I can successfully use the Eval function and get it to call any function with...
10
by: Gordon | last post by:
I have a script that creates new objects based on the value of a form field. Basically, the code looks like this. eval ('new ' + objType.value + '(val1, val2, val3'); objType is a select with...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...

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.