473,569 Members | 2,813 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Trim Each textbox control - Repost

HI

I'm trying to iterate through all the textboxes on a webpage and trim
them for spaces.

i.e. If a user enters " hello world " we correct it to "hello
world"

So far I've come up with this:

-------------------------------------------------------------------------------

'Trim all textboxes
Dim ThisControl As System.Web.UI.C ontrol
For Each ThisControl In Me.Controls

If ThisControl.Get Type().ToString () =
"system.Web.UI. WebControls.Tex tBox" Then

ThisControl.tex t = Trim(ThisContro l.text)
'Above line is wrong syntax, I want to trim the textbox here, but I'm
stuck! Please help...

End If

Next ThisControl

-------------------------------------------------------------------------------

The problem I have is not really with the trim function. It's the fact
that I cannot update the control text value. It won't allow the .text
property at all in this example because "thiscontro l" is not actually
aware that the control assigned to it is actually a textbox. Is there a
way to tell it it's a textbox so I can access this property, or is there
another way around this?
Can you help?

Many Thanks!

Alex
Nov 18 '05 #1
2 2555
Hi,

here is an example how to loop through controls on the Page:
http://www.aspnet101.com/aspnet101/tips.aspx?id=97

If you want to access Text property, you need to have typed reference (cast
it to TextBox with CType and set the value to the property).

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist
http://blogs.aspadvice.com/joteke

"Alex Shirley" <po******@alexs hirley.com> wrote in message
news:e9******** *************** ***@posting.goo gle.com...
HI

I'm trying to iterate through all the textboxes on a webpage and trim
them for spaces.

i.e. If a user enters " hello world " we correct it to "hello
world"

So far I've come up with this:

-------------------------------------------------------------------------- -----
'Trim all textboxes
Dim ThisControl As System.Web.UI.C ontrol
For Each ThisControl In Me.Controls

If ThisControl.Get Type().ToString () =
"system.Web.UI. WebControls.Tex tBox" Then

ThisControl.tex t = Trim(ThisContro l.text)
'Above line is wrong syntax, I want to trim the textbox here, but I'm
stuck! Please help...

End If

Next ThisControl

-------------------------------------------------------------------------- -----
The problem I have is not really with the trim function. It's the fact
that I cannot update the control text value. It won't allow the .text
property at all in this example because "thiscontro l" is not actually
aware that the control assigned to it is actually a textbox. Is there a
way to tell it it's a textbox so I can access this property, or is there
another way around this?
Can you help?

Many Thanks!

Alex

Nov 18 '05 #2
Thanks Teemu

However I'm still stuck with the casting the object I've discovered in
a for next loop to a textbox so I can access its properties in
VB/ASP.Net... dumb I know, but I've looked everywhere for an answer,
but obviously not in the right places!

So far I've got this code:

-----------------------------------

Dim ThisControl As System.Web.UI.C ontrol
Dim txtControl As TextBox

For Each ThisControl In Me.Controls
If ThisControl.Get Type().ToString () =
"system.Web.UI. WebControls.Tex tBox" Then
txtControl = CType(ThisContr ol, TextBox) ' am I casting this
correctly???
txtControl.Text = "I'vechange d" 'Doesn't work
End If
Next ThisControl

-----------------------------------

I tried ThisControl = CType(ThisContr ol, TextBox), but the properties
won't appear for thiscontrol.

Sorry but can you or somebody help in this casting so I can update or
get the text property?

Thanks

Alex

"Teemu Keiski" <jo****@aspalli ance.com> wrote in message news:<el******* *******@TK2MSFT NGP11.phx.gbl>. ..
Hi,

here is an example how to loop through controls on the Page:
http://www.aspnet101.com/aspnet101/tips.aspx?id=97

If you want to access Text property, you need to have typed reference (cast
it to TextBox with CType and set the value to the property).

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist
http://blogs.aspadvice.com/joteke

"Alex Shirley" <po******@alexs hirley.com> wrote in message
news:e9******** *************** ***@posting.goo gle.com...
HI

I'm trying to iterate through all the textboxes on a webpage and trim
them for spaces.

i.e. If a user enters " hello world " we correct it to "hello
world"

So far I've come up with this:

--------------------------------------------------------------------------

-----

'Trim all textboxes
Dim ThisControl As System.Web.UI.C ontrol
For Each ThisControl In Me.Controls

If ThisControl.Get Type().ToString () =
"system.Web.UI. WebControls.Tex tBox" Then

ThisControl.tex t = Trim(ThisContro l.text)
'Above line is wrong syntax, I want to trim the textbox here, but I'm
stuck! Please help...

End If

Next ThisControl

--------------------------------------------------------------------------

-----

The problem I have is not really with the trim function. It's the fact
that I cannot update the control text value. It won't allow the .text
property at all in this example because "thiscontro l" is not actually
aware that the control assigned to it is actually a textbox. Is there a
way to tell it it's a textbox so I can access this property, or is there
another way around this?
Can you help?

Many Thanks!

Alex

Nov 18 '05 #3

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

Similar topics

3
10682
by: Andy B | last post by:
I've tried using Trim or RTrim to strip trailing space characters from my data. When I check on the transformed data space characters are still there. We have an address table containing two fields: BuildName and RoadName. Both have the following properties: size 50, not indexed, not required, allowed zero length. Some records have...
2
285
by: Amil Hanish | last post by:
I have a form with 5 TextBox controls. One of them is a password TextBox. When the form is submitted, one of the other fields might have an invalid format; on the repost showing the error in the other field, I want to restore the password value into the password TextBox...without the user re-entering it. Seems like, by default, a password...
2
1303
by: Alex Shirley | last post by:
HI I'm trying to iterate through all the textboxes on a webpage and trim them for spaces. i.e. If a user enters " hello world " we correct it to "hello world" So far I've come up with this:
3
2734
by: FlyerN87 | last post by:
For some reason this command will not trim the names shown in the fields listed. I'm trying to do this in a text box on a report. I've done this fairly succesfully in other reports but I must have done something wrong here.... I've tried both of these... =Trim( & ) =Trim( &", "& )
2
1095
by: John | last post by:
Hi all, I have a gridview with bound controls and some column templates. One of these column templates is a textbox which is used for running totals. I don't want the user to edit this so I merely set the enabled property to false. The problem I'm having is that when the page posts back to the server then back to the client again, the...
11
7727
by: Joe | last post by:
Hello All, I have an ASP.NET page with one Textbox (SearchTextBox) and one ImageButton (SearchButton) server controls. The user can type search text in SearchTextBox and click SearchButton and the web server performs a database query and displays the results. All of this works fine. I want the user to be able to press the Enter key...
7
2409
by: Woody Splawn | last post by:
It is hard for me to imagine a time when you would not want to have the data in a textbox control trimmed. I am hoping there is some sort of switch that can be set for all text boxes so that when the user leaves the text box it gets trimmed. Is there such a thing. If not, does this mean I need to write some sort of trimming code for each...
8
1383
by: Woody Splawn | last post by:
Could someone give me a suggestion for writing generic code in a validating event for trimming the value of a textbox entry? I thought something like the following might work but it does not. Dim txt As TextBox = DirectCast(sender, TextBox) txt.Text = Trim(txt.Text) I get an invalid cast error
1
1164
OuTCasT
by: OuTCasT | last post by:
Hi everyone. i need to trim text in a textbox. i populate a textbox which is for example company.mdf Now is need to trim the textbox so that it will show company and not company.mdf
0
7703
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
7618
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
7926
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7983
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...
1
5514
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
5223
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3657
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2117
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
946
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.