Wrox Programmer Forums
|
ASP.NET 1.1 As of 10/6/2005, this forum is locked as part of the reorganization described here: http://p2p.wrox.com/topic.asp?TOPIC_ID=35394. No posts have been deleted. Open ongoing discussions from the last week have been moved to either ASP.NET 1.0 and 1.1 Beginners http://p2p.wrox.com/asp-net-1-0-1-1-basics-60/ or ASP.NET 1.0 and 1.1 Professional. http://p2p.wrox.com/forum.asp?FORUM_ID=50. See my sticky post inside for more.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.1 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 12th, 2004, 02:59 PM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 218
Thanks: 0
Thanked 0 Times in 0 Posts
Default Eval in VB.NET

I have a statement that I want to make dynamic.

lblFundSource2.Visible = True

I want to be able to substitute a variable for the "2". I have done this previously in Javascript with the eval() function.
Something like: eval("lblFundSource" + myInt + ".Visible") = True; where myInt = 2.

Is there an equivalent in .NET?

Thanks in advance for your comments
-- Colonel



- - - - - - - - - - - - - - - - - - - - - - -
In God we trust, everything else we test.
 
Old May 13th, 2004, 12:49 PM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 218
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I found the answer if anyone wants to know--

The FindControl() function was the answer.

dim myLabel as Label = FindControl("lblFundSource" & myInt)
myLabel.visible = True

- - - - - - - - - - - - - - - - - - - - - - -
In God we trust, everything else we test.
 
Old May 13th, 2004, 12:55 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Be aware that FindControl returns a generic Control, not directly the type of control you're expecting.

So, in your case since the Visible property is defined in the parent class Control, you have no problems. If, for example, you would have tried to set the Text (as defined in the Label "child", and not in the parent "Control"), you have to cast it first:

Dim myLabel As Label = CType(FindControl("lblFundSource" & myInt), Label)
myLabel.Visible = True

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to: Over & Over by Moloko (Track 10 from the album: Statues) What's This?
 
Old May 13th, 2004, 01:55 PM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 218
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks!

- - - - - - - - - - - - - - - - - - - - - - -
In God we trust, everything else we test.





Similar Threads
Thread Thread Starter Forum Replies Last Post
vb.net 2008 re: VB.NET databases book bigbearjeff VB.NET 0 June 2nd, 2008 01:22 PM
VB.Net question on Windows VB.Net datagrids dmsousa VS.NET 2002/2003 1 January 19th, 2005 02:45 PM
Eval??? tsimsha Classic ASP Basics 2 January 17th, 2005 10:02 PM
vb.net 2002 OR vb.net 2003 metalaaron VB.NET 2002/2003 Basics 0 August 5th, 2003 10:00 AM
vb.net 2002 - vb.net 2003 book metalaaron Wrox Book Feedback 0 August 2nd, 2003 10:46 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.