What everyone else said is accurate, but I wanted to point out that you'll
need to recursively scan through all controls - your code doesn't show that
you are doing this (doesn't show that you aren't either).
private sub StripFromTextbox(parent as Control, searchFor as string,
replaceWith as string)
for each c as control in parent
if c.HasControls then
StripFromTextbox(c, searchFor, replaceWith)
end if
if c is TextBox then
dim t as textbox = ctype(c, textbox)
t.text = t.text.replace(searchFor, replaceWith)
end if
end sub
or something to that effect...
Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/
"VB Programmer" <Do*****************@jEmail.com> wrote in message
news:ee**************@tk2msftngp13.phx.gbl...
How can I loop thru all textboxes on a form?
I want to remove any single quotes in the data entry. I was thinking
something like this:
For Each c As Control In Me.Controls
Dim t As TextBox = CType(c, TextBox)
t.Text = t.Text.Replace("'", "")
Next
But the CType is giving me a 'Specified cast is not valid'.
Thanks.