473,545 Members | 1,924 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Looping through textboxes - error in my code?

Hi - I'm trying to loop through the textboxes on a page to unlock them for
editing. The Enabled property is set to false, and the following code is on
an 'Edit' button on the form. Can anyone tell me why it doesn't work?

Thanks

Nick.
Code:
Dim frmCtrl As Control

For Each frmCtrl In Me.Controls

If TypeOf frmCtrl Is System.Web.UI.W ebControls.Text Box Then

Dim textbox As System.Web.UI.W ebControls.Text Box = frmCtrl

textbox.Enabled = True

End If

Next
Nov 18 '05 #1
4 1296
In data Thu, 1 Jul 2004 16:39:38 +0100, Nick ha scritto:
Hi - I'm trying to loop through the textboxes on a page to unlock them for
editing. The Enabled property is set to false, and the following code is on
an 'Edit' button on the form. Can anyone tell me why it doesn't work?

Thanks

Nick.
Code:
Dim frmCtrl As Control

For Each frmCtrl In Me.Controls

If TypeOf frmCtrl Is System.Web.UI.W ebControls.Text Box Then

Dim textbox As System.Web.UI.W ebControls.Text Box = frmCtrl

textbox.Enabled = True

End If

Next


Why instead of this:

Dim textbox As System.Web.UI.W ebControls.Text Box = frmCtrl
textbox.Enabled = True

you don't use this:

DirectCast(frmC trl, System.Web.UI.W ebControls.Text Box).Enabled = True

?
Nov 18 '05 #2
Hi - I tried changing the code - but same result. Code runs fine with no
errors, but doesn't enable the textboxes.
Does the postback change them back to enabled=false as that is the default
setting in the IDE??

Nick

"Crosta" <Cr****@Crosta. Crosta> wrote in message
news:wh******** *************** *****@40tude.ne t...
In data Thu, 1 Jul 2004 16:39:38 +0100, Nick ha scritto:
Why instead of this:

Dim textbox As System.Web.UI.W ebControls.Text Box = frmCtrl
textbox.Enabled = True

you don't use this:

DirectCast(frmC trl, System.Web.UI.W ebControls.Text Box).Enabled = True

?

Nov 18 '05 #3
Tee
I think I knew what you need.
I was having the same problem last time, for each control loop work in
windows form but not web form. In web forms, you need to use a recursive
function to search thru all the levels. I'm not very sure how to explain it,
I will post a code that hope can help you here.
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click

EnableTextboxes (Controls)

End Sub

Private Sub EnableTextboxes (ByVal col As ControlCollecti on)

If (col Is Nothing) Then

Return

End If

Dim c As Control

For Each c In col

If TypeOf c Is TextBox Then

CType(c, TextBox).Enable d = True

End If

ChangeTextboxes (c.Controls)

Next

End Sub

With this recursive function, it will search thru all levels of object, eg:
the texbox is inside a panel, a panel is inside a form
if you don't use recursive function, you only get those textboxes in the
form but not the panel.
HTH,
Tee


"Nick" <Ni**@NTWorks.n o.spam.fsnet.co .uk> wrote in message
news:eg******** ******@TK2MSFTN GP09.phx.gbl...
Hi - I tried changing the code - but same result. Code runs fine with no
errors, but doesn't enable the textboxes.
Does the postback change them back to enabled=false as that is the default
setting in the IDE??

Nick

"Crosta" <Cr****@Crosta. Crosta> wrote in message
news:wh******** *************** *****@40tude.ne t...
In data Thu, 1 Jul 2004 16:39:38 +0100, Nick ha scritto:
Why instead of this:

Dim textbox As System.Web.UI.W ebControls.Text Box = frmCtrl
textbox.Enabled = True

you don't use this:

DirectCast(frmC trl, System.Web.UI.W ebControls.Text Box).Enabled = True

?


Nov 18 '05 #4
Thanks - that was exactly what I was looking for!

Nick

"Tee" <th*@streamyx.c om> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
I think I knew what you need.
I was having the same problem last time, for each control loop work in
windows form but not web form. In web forms, you need to use a recursive
function to search thru all the levels. I'm not very sure how to explain it, I will post a code that hope can help you here.
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click

EnableTextboxes (Controls)

End Sub

Private Sub EnableTextboxes (ByVal col As ControlCollecti on)

If (col Is Nothing) Then

Return

End If

Dim c As Control

For Each c In col

If TypeOf c Is TextBox Then

CType(c, TextBox).Enable d = True

End If

ChangeTextboxes (c.Controls)

Next

End Sub

With this recursive function, it will search thru all levels of object, eg: the texbox is inside a panel, a panel is inside a form
if you don't use recursive function, you only get those textboxes in the
form but not the panel.
HTH,
Tee

Nov 18 '05 #5

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

Similar topics

11
3103
by: ian.davies52 | last post by:
Is there anything I can do about the apparent limit on the number of textboxes that have calculations as their control source on a form or report in ms-access? I have a query that pulls together all the fields from two tables, each with about 20 fields. I then have a statistics form that has the query as its source and the form has 273...
2
1992
by: ozgirl via AccessMonster.com | last post by:
Hi, hopeing someone can help me here... I have a deductions table and form and want to be able to add many deductions to the table by having only a few fields on the form form fields: deduction ID, start date, end date and amount what i want to be able to do is keep adding a deduction each 7 days from the
3
1557
by: Belee | last post by:
I always clear textboxes by using eg this.txtName.clear(); What is the best way of doing this to about 20 boxes or asignig values to them in C#.
4
277
by: Deasun O'Donnachadha | last post by:
Good evening, I have a panel with a number of labels and textboxes. I want to set the text boxes to readonly = false. This is what I have; Dim objTxtBox As New TextBox For Each objTxtBox In pnl_FB_Details.Controls objTxtBox.ReadOnly = False Next
4
8751
by: bwalke | last post by:
I am developing a web form which is going to be used for manufacturing input. The form uses a DataList which list a batch of parts that may range anywhere from 1-9 parts. The DataList contains 6 textboxes pre-fill with data (reason for using datalist) which will capture user input and changes to the textboxes. So the 6 textboxes in columns...
2
6930
by: Lenster | last post by:
I'm having problems using the errorprovider in VB.NET to automatically display an error icon next to textboxes bound to the same dataset as the errorprovider. The sequence of events is : Build a dataset containing a single table. Bind the textboxes on a windows form to the datatable. Bind the errorprovider control to the same datatable....
0
1289
by: jobs | last post by:
I have a many many pages with many formviews with many textboxes in them. The matrix of types of validation I need to do is a giant mess so please don't judge the code you are about to see - I don't want to use the new and native validatongroups .. well at least I want to know what I'm trying is not possible. I'm trying to loop through the...
6
6073
by: jobs | last post by:
This code was working, but then stopped working. I don't think I completely understand it. I pass it a formview name and it would loop through checking the value of textboxes. problem is now as i debug it, it's telling me there are only a count of 3 controls in that for loop. and they have clientid values like: ...
0
713
by: gurmeet07 | last post by:
if i have smthing like............. if (ht.ContainsKey(textBox7.Text)) { object array = (object)ht; textBox1.Text = (string)array; textBox2.Text = (string)array; textBox3Text = (string)array; //And so on }
0
7478
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7410
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7923
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7437
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7773
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5984
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5343
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1025
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.