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

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.WebControls.TextBox Then

Dim textbox As System.Web.UI.WebControls.TextBox = frmCtrl

textbox.Enabled = True

End If

Next
Nov 18 '05 #1
4 1287
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.WebControls.TextBox Then

Dim textbox As System.Web.UI.WebControls.TextBox = frmCtrl

textbox.Enabled = True

End If

Next


Why instead of this:

Dim textbox As System.Web.UI.WebControls.TextBox = frmCtrl
textbox.Enabled = True

you don't use this:

DirectCast(frmCtrl, System.Web.UI.WebControls.TextBox).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.net...
In data Thu, 1 Jul 2004 16:39:38 +0100, Nick ha scritto:
Why instead of this:

Dim textbox As System.Web.UI.WebControls.TextBox = frmCtrl
textbox.Enabled = True

you don't use this:

DirectCast(frmCtrl, System.Web.UI.WebControls.TextBox).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(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

EnableTextboxes(Controls)

End Sub

Private Sub EnableTextboxes(ByVal col As ControlCollection)

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).Enabled = 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.no.spam.fsnet.co.uk> wrote in message
news:eg**************@TK2MSFTNGP09.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.net...
In data Thu, 1 Jul 2004 16:39:38 +0100, Nick ha scritto:
Why instead of this:

Dim textbox As System.Web.UI.WebControls.TextBox = frmCtrl
textbox.Enabled = True

you don't use this:

DirectCast(frmCtrl, System.Web.UI.WebControls.TextBox).Enabled = True

?


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

Nick

"Tee" <th*@streamyx.com> wrote in message
news:%2****************@TK2MSFTNGP11.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(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

EnableTextboxes(Controls)

End Sub

Private Sub EnableTextboxes(ByVal col As ControlCollection)

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).Enabled = 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
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...
2
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:...
3
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
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...
4
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 ...
2
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 : ...
0
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...
6
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...
0
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;...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
0
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...

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.