473,320 Members | 2,098 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,320 software developers and data experts.

Evaluating a variable name

Hi everyone,

I've run into another road block that google.com isn't able to solve
since I don't even know where to start when searching.

In my webapp, a certain number of table rows containing textboxes is
displayed depending on a number chosen by the user. For example, if
the user chooses 3, there will be three rows displayed with 4 texts
boxes in each row. Using a for loop to create the textboxs, I've
appended a number to the ID of each of the textbox. so Length1,
Width1, Height1, Length2, Width2, Height2 etc...

This is all fine and dandy, but I can't figure out how to reference
these textboxes (to get the information of them and into a struct
stored in a session variable). I recall in ASP that there was some
function which allowed you to evaluate a string and have it behave as
though you entered a proper variable name. For example, I'm looking
for something to convert "Length" + counter.ToString() into something
the compiler will process as a variable. (so the compiler only sees
Length1, Length2 etc... (seeing it as a proper variable name, not as
string).

Any help would be appreciated.

Thanks,
Nicholas

Jun 24 '06 #1
6 2605
<en****@gmail.com> wrote:
I've run into another road block that google.com isn't able to solve
since I don't even know where to start when searching.

In my webapp, a certain number of table rows containing textboxes is
displayed depending on a number chosen by the user. For example, if
the user chooses 3, there will be three rows displayed with 4 texts
boxes in each row. Using a for loop to create the textboxs, I've
appended a number to the ID of each of the textbox. so Length1,
Width1, Height1, Length2, Width2, Height2 etc...

This is all fine and dandy, but I can't figure out how to reference
these textboxes (to get the information of them and into a struct
stored in a session variable). I recall in ASP that there was some
function which allowed you to evaluate a string and have it behave as
though you entered a proper variable name. For example, I'm looking
for something to convert "Length" + counter.ToString() into something
the compiler will process as a variable. (so the compiler only sees
Length1, Length2 etc... (seeing it as a proper variable name, not as
string).


Instead of using different variables for each textbox, why not just
have an array of them?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jun 24 '06 #2
There isn't much need for that. The method he is looking for is the
FindControl method on the Page class, which will find the control based on
the control's identifier.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
<en****@gmail.com> wrote:
I've run into another road block that google.com isn't able to solve
since I don't even know where to start when searching.

In my webapp, a certain number of table rows containing textboxes is
displayed depending on a number chosen by the user. For example, if
the user chooses 3, there will be three rows displayed with 4 texts
boxes in each row. Using a for loop to create the textboxs, I've
appended a number to the ID of each of the textbox. so Length1,
Width1, Height1, Length2, Width2, Height2 etc...

This is all fine and dandy, but I can't figure out how to reference
these textboxes (to get the information of them and into a struct
stored in a session variable). I recall in ASP that there was some
function which allowed you to evaluate a string and have it behave as
though you entered a proper variable name. For example, I'm looking
for something to convert "Length" + counter.ToString() into something
the compiler will process as a variable. (so the compiler only sees
Length1, Length2 etc... (seeing it as a proper variable name, not as
string).


Instead of using different variables for each textbox, why not just
have an array of them?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Jun 24 '06 #3
Nicholas Paldino [.NET/C# MVP] <mv*@spam.guard.caspershouse.com> wrote:
There isn't much need for that. The method he is looking for is the
FindControl method on the Page class, which will find the control based on
the control's identifier.


You can certainly do that - but I'd argue that using an array is a more
elegant solution than having multiple variables.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jun 24 '06 #4
I agree, but with FindControl, you don't need to have any variables at
all, not even the one variable for the array.

When you add a control to ASP, it assigns an id to it (which is the same
name as the reference in the code-behind). You just have to pass this id to
the FindControl method to get the reference to it. In this case, I think it
would be better, since the OP would not have to take the controls and manage
them by placing them in the array. He just has to name them appropriately.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Nicholas Paldino [.NET/C# MVP] <mv*@spam.guard.caspershouse.com> wrote:
There isn't much need for that. The method he is looking for is the
FindControl method on the Page class, which will find the control based
on
the control's identifier.


You can certainly do that - but I'd argue that using an array is a more
elegant solution than having multiple variables.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Jun 25 '06 #5
Nicholas Paldino [.NET/C# MVP] <mv*@spam.guard.caspershouse.com> wrote:
I agree, but with FindControl, you don't need to have any variables at
all, not even the one variable for the array.

When you add a control to ASP, it assigns an id to it (which is the same
name as the reference in the code-behind). You just have to pass this id to
the FindControl method to get the reference to it. In this case, I think it
would be better, since the OP would not have to take the controls and manage
them by placing them in the array. He just has to name them appropriately.


What exactly do you mean by "the same name as the reference in the
code-behind"? It sounds like you mean the name of a variable...

I don't know how exactly it would all work in ASP.NET, but certainly in
Windows Forms (where I dislike using the designer anyway) an array
would make more sense to me than separate named variables.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jun 25 '06 #6
Thanks for all the assistance, everyone has been very helpful.

Nicholas

Jon wrote:
Nicholas Paldino [.NET/C# MVP] <mv*@spam.guard.caspershouse.com> wrote:
I agree, but with FindControl, you don't need to have any variables at
all, not even the one variable for the array.

When you add a control to ASP, it assigns an id to it (which is the same
name as the reference in the code-behind). You just have to pass this id to
the FindControl method to get the reference to it. In this case, I think it
would be better, since the OP would not have to take the controls and manage
them by placing them in the array. He just has to name them appropriately.


What exactly do you mean by "the same name as the reference in the
code-behind"? It sounds like you mean the name of a variable...

I don't know how exactly it would all work in ASP.NET, but certainly in
Windows Forms (where I dislike using the designer anyway) an array
would make more sense to me than separate named variables.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too


Jun 26 '06 #7

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

Similar topics

3
by: Kevin Rollo | last post by:
I'm playing with a generic routine to export data, the concept is to have a list of data driven templates defining what fields to output. Evaluating a simple variable field name in the function...
6
by: Raed Sawalha | last post by:
i have the following case a MyClass class has method with 2 arguments as void SetProp(string varname,string varvalue); in MyClass i have following members string...
6
by: markoniinimaki | last post by:
Hi, suppose I get a document name a.xml and a path //foo/bar (which nodes eventually to read from it) from another doc. Problem: how to combine them so that the whole expression gets...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.