Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Automatically Trim Spaces for DataBound TextBoxes

Posted on 2006-04-04
1
Medium Priority
?
401 Views
Last Modified: 2012-05-05
What I'd like to do is automatically trim spaces (or "space characters") from all text boxes just before the data is sent to the database.

I can do that with a global TextChanged even handler, but I'd rather do it just once instead of every time the "text changes".

Is there any event I can catch that might give me an opprotunity to trim() all the strings before they go into the DB/DataSet?

Thanks!
0
Comment
Question by:mitchvincent
1 Comment
 
LVL 64

Accepted Solution

by:
Fernando Soto earned 2000 total points
ID: 16371410
Hi mitchvincent;

You can use the Validating event handler to make the change once. It fires just before losing focus.

    Private Sub TextBox_Validating(ByVal sender As Object, _
        ByVal e As System.ComponentModel.CancelEventArgs) Handles _
        TextBox1.Validating, TextBox2.Validating

        Dim tb As TextBox = CType(sender, TextBox)
        tb.Text = tb.Text.Trim()

    End Sub

Fernando
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Loops Section Overview
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses
Course of the Month13 days, 23 hours left to enroll

581 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question