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

locating and changing multiple controls on a page

TB
Hi All:

How do I find all textboxes on a page and change a certain property
('enabled' for example) on each of them?

I thought of doing something like this:
sub changemytexboxes()
Dim mytxb As TextBox
For Each mytxb In Me.Controls
ctrlname.Enabled = False
Next
End sub

But when I do that, I get a casting error.

Or do I have to use findcontrol? If so, how?

Any advice would be highly appreciated.

Thanks

TB

Jun 11 '06 #1
3 1037
On 11 Jun 2006 15:01:06 -0700, TB wrote:
I thought of doing something like this:
sub changemytexboxes()
Dim mytxb As TextBox Dim myctrl As Control
For Each mytxb In Me.Controls For Each myctrl in Me.Controls
If TypeOf myctrl Is TextBox then
CType(myctrl, TextBox).Enabled = False
End If
Next ctrlname.Enabled = False
Next
End sub

But when I do that, I get a casting error.


Yes, because the objects are stored as Controls, even though they may be
TextBoxes, also there may be controls on the page that are not TextBoxes,
so that would not be what you were looking for.
Jun 11 '06 #2
You can loop through them using control tree recursion as I've shown in this
code sample:
http://SteveOrr.net/faq/ControlTreeRecursion.aspx

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net
"TB" <tr********@gmail.com> wrote in message
news:11**********************@f6g2000cwb.googlegro ups.com...
Hi All:

How do I find all textboxes on a page and change a certain property
('enabled' for example) on each of them?

I thought of doing something like this:
sub changemytexboxes()
Dim mytxb As TextBox
For Each mytxb In Me.Controls
ctrlname.Enabled = False
Next
End sub

But when I do that, I get a casting error.

Or do I have to use findcontrol? If so, how?

Any advice would be highly appreciated.

Thanks

TB

Jun 12 '06 #3
TB
Steve,

It worked perfectly!. Thanks a lot. I changed "Page.Controls" to
'Me.Controls' so that the code would run inside a usercontrol on that
page. I hope that was the correct thing to do.

BTW, you got a very interesting web site.

TB

Steve C. Orr [MVP, MCSD] wrote:
You can loop through them using control tree recursion as I've shown in this
code sample:
http://SteveOrr.net/faq/ControlTreeRecursion.aspx

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net


Jun 12 '06 #4

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

Similar topics

1
by: Jaweed | last post by:
Hi I'm developing an ASP.NET app in Visual studio (using C# for code behind). My question is fairly simple (i think). When I go to the code behind page, the controls in the html page are made...
1
by: .Net Newbie | last post by:
I am relatively new to .Net and have been coding an intranet site for my employer for a couple of months. I am currently stuck coding in a text-editor called EditPlus without access to the VS.Net...
0
by: Johann Blake | last post by:
I'm having trouble grasping how ASP.NET correctly locates resources. There is plenty of documentation on this subject but some things are not clear at all. In my ASP.NET application, I have...
3
by: Damon | last post by:
I am working on a site in which I would like to have two dropdowns that will allow a user to navigate through the administrative pages of the site. The first would allow the user to choose the...
3
by: qwerty | last post by:
I´m new to ASP.Net. My workmate has some experience with it. He claimed that in ASP.Net working with frames is much simpler than it was ASP. I asked explanation but he couldn't give me such. (a...
3
by: Nathan Sokalski | last post by:
When I view any page in my application a second time, I recieve the following error: System.Web.TraceContext.AddNewControl(String id, String parentId, String type, Int32 viewStateSize) +313...
11
by: Ranginald | last post by:
This question is about how to handle an .aspx page that references multiple methods and where to store these methods (e.g. one codefile or multiple codefiles). PREFACE ======== I have a simple...
1
by: =?Utf-8?B?TWF5?= | last post by:
We are getting WebForm_DoPostBackWithOptions is not defined and other Java script errors related to WebResource.axd file. I narrowed down the problem and found out the cause but can't come up with...
4
by: Ty | last post by:
Hi all Short version of my problem: i have a Datagrid (Flexgrid from ComponentOne) with a Datatable as source. I need to search a row in the datatable, using a primary key column in the...
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
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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...

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.