By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,552 Members | 893 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,552 IT Pros & Developers. It's quick & easy.

Finding controls on a panel

P: n/a
Is there a way to get the names of all of the textboxes that are placed on a
panel?

I have several panels on my .NET application, each with several textbox
controls. I would like to get all of the names of the textboxes and clear
to text values without manually typing out all of the names. Is there an
easy way to specify the panel that these controls are placed in and get
those names?

something like

for each textbox on panel1
textbox.value =""
next

Thanks,
Aaron
Nov 21 '05 #1
Share this Question
Share on Google+
12 Replies


P: n/a
Aaron

You are there almost

for each textbox on panel1
textbox.value =""
next

for each txb as control on panel1.controls
if typeof txb Is textbox then
txb.text = ""
end if
next

I hope this helps?

Cor
Nov 21 '05 #2

P: n/a
If I use this code:

Sub BetaClearTextBoxes(ByVal PanelName As Panel)
Dim txb As Control
For Each txb In PanelName.Controls
If TypeOf txb Is TextBox Then
txb.text = ""
End If
Next
End Sub

Intellisense gives me an error stating that "text" is not a member of
"Control".
If I use this code (Dim txb as textbox instead of control)

Sub BetaClearTextBoxes(ByVal PanelName As Panel)
Dim txb As TextBox
For Each txb In PanelName.Controls
If TypeOf txb Is TextBox Then
txb.text = ""
End If
Next
End Sub

I get Specified cast is not valid.
This errors out on the for each txb line.

Any ideas?

Thanks,
Aaron

"Cor Ligthert" <no**********@planet.nl> wrote in message
news:et**************@tk2msftngp13.phx.gbl...
Aaron

You are there almost

for each textbox on panel1
textbox.value =""
next

for each txb as control on panel1.controls
if typeof txb Is textbox then
txb.text = ""
end if
next

I hope this helps?

Cor

Nov 21 '05 #3

P: n/a

"Aaron" <aa***@jonharvey.com> wrote in message
news:%2***************@TK2MSFTNGP11.phx.gbl...
If I use this code:

Sub BetaClearTextBoxes(ByVal PanelName As Panel)
Dim txb As Control
For Each txb In PanelName.Controls
If TypeOf txb Is TextBox Then
txb.text = ""
End If
Next
End Sub

Intellisense gives me an error stating that "text" is not a member of
"Control".


Try

DirectCast(txb, TextBox).Text = ""
Nov 21 '05 #4

P: n/a
Yeas, this code works:
Sub BetaClearTextBoxes(ByVal PanelName As Panel)
Dim txb As Control
For Each txb In PanelName.Controls
If TypeOf txb Is TextBox Then
DirectCast(txb, TextBox).Text = ""
End If
Next
End Sub

Thanks for the help! I had never heard of DirectCast...

Aaron

"Jeff Johnson [MVP: VB]" <i.***@enough.spam> wrote in message
news:Op*************@TK2MSFTNGP09.phx.gbl...

"Aaron" <aa***@jonharvey.com> wrote in message
news:%2***************@TK2MSFTNGP11.phx.gbl...
If I use this code:

Sub BetaClearTextBoxes(ByVal PanelName As Panel)
Dim txb As Control
For Each txb In PanelName.Controls
If TypeOf txb Is TextBox Then
txb.text = ""
End If
Next
End Sub

Intellisense gives me an error stating that "text" is not a member of
"Control".


Try

DirectCast(txb, TextBox).Text = ""

Nov 21 '05 #5

P: n/a
brrrrrrrrrr I typed it direct in the message, this error I make seldom

And I knew I was missing something.

:-)

Thanks

Cor
Nov 21 '05 #6

P: n/a

"Cor Ligthert" <no**********@planet.nl> wrote in message
news:el**************@tk2msftngp13.phx.gbl...
brrrrrrrrrr I typed it direct in the message, this error I make seldom


We call that "air code."
Nov 21 '05 #7

P: n/a
Aaron,

I first was thinking I was making a quick typing mistake, however it can not
give an error.

Textbox derives text from control and therefore casting is not necessary.
So text is a property from Control. So how can you get the message that text
is not a property from Control.

I am curious why you got this?

Cor
Nov 21 '05 #8

P: n/a
Jeff,
brrrrrrrrrr I typed it direct in the message, this error I make seldom


We call that "air code."

It was no typing mistake, when I answered it was late in evening here, so I
was direct thinking on an error. However casting should not be necessary
here because Text is a property from Control and I stopped to type the
casting with that and did that automaticly as well in this message.

Cor
Nov 21 '05 #9

P: n/a

"Cor Ligthert" <no**********@planet.nl> wrote in message
news:eF**************@TK2MSFTNGP11.phx.gbl...
brrrrrrrrrr I typed it direct in the message, this error I make seldom
We call that "air code."

It was no typing mistake, when I answered it was late in evening here, so

I was direct thinking on an error. However casting should not be necessary
here because Text is a property from Control and I stopped to type the
casting with that and did that automaticly as well in this message.


Hmmm, you're right. It looks like it should work. I'll test it when I get a
chance.
Nov 21 '05 #10

P: n/a
Text is not a property of control. At least not in asp.net.

If I do :
Dim C as control
C.text does not exist

Aaron

"Cor Ligthert" <no**********@planet.nl> wrote in message
news:uA**************@TK2MSFTNGP10.phx.gbl...
Aaron,

I first was thinking I was making a quick typing mistake, however it can not give an error.

Textbox derives text from control and therefore casting is not necessary.
So text is a property from Control. So how can you get the message that text is not a property from Control.

I am curious why you got this?

Cor

Nov 21 '05 #11

P: n/a
* "Aaron" <aa***@jonharvey.com> scripsit:
Text is not a property of control. At least not in asp.net.


ACK. Then I would suggest to cast to the type of the class that
provides the property.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #12

P: n/a
Aaron,

When in this newsgroup is not told it is a webform than it is by default a
windowform when there are 2 possibilities.

In your message you did not tell, not a member of "web.ui.control" however
even "control". A panel is as well on a windowform as on a webform.

When it is a webform, than you would do that casting to get the right
object.

However I am glad you messaged it because I did absolute not understand it,
and was not thinking about a webform, because I thought that it needs
something more on a webform. Now I saw that that more is not when it is on a
panel but when it is direct on the page.

:-)

Cor
Text is not a property of control. At least not in asp.net.

If I do :
Dim C as control
C.text does not exist

Aaron

"Cor Ligthert" <no**********@planet.nl> wrote in message
news:uA**************@TK2MSFTNGP10.phx.gbl...
Aaron,

I first was thinking I was making a quick typing mistake, however it can

not
give an error.

Textbox derives text from control and therefore casting is not necessary. So text is a property from Control. So how can you get the message that

text
is not a property from Control.

I am curious why you got this?

Cor


Nov 21 '05 #13

This discussion thread is closed

Replies have been disabled for this discussion.