Click here to Skip to main content
15,890,336 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello Professionals,

I am making an application using asp.net-mvc with C#.
There are many pages (views as per MVC) and every page have few textboxes.

I want to apply trim function to all the textboxes.
One single and inappropriate solution is to go to every page and apply jquery's trim function to each and every textbox.


It would be of great help to me if anyone can suggest me a better way and efficient way.

Regards,
Shivang.
Posted
Comments
Sergey Alexandrovich Kryukov 19-Mar-13 9:49am    
Why? What seems to be a problem? Why you did not solve it so far? Any difficulty, in particular?
—SA
ShivangDesai 20-Mar-13 0:34am    
Problem:
Initially trim function was not applied but now I want to apply it due to some constraints.
Its cumbersome to go to each and every textbox and apply trim(). So I just wanted to know if there is any generic functionality that can be applied as a whole , where I don't need to go to each and every textbox. :-)
Sergey Alexandrovich Kryukov 20-Mar-13 1:30am    
Not clear. If you really want to trim each and every text box (why, by the way), this is what you should do. Why cumbersome? Do you want all text boxes to trim themselves? Well, instruct them to do so. :-)

What's the problem? As if you never heard of recursion and loops.

Looking for some "generic functionality" is wrong way of thinking. Have a problem? Solve it with your own hands. And you did not even explain what's your problem. Act be definition. Is there something you don't know? Or you need more bravery?

—SA
ShivangDesai 20-Mar-13 1:37am    
@ Sergey :
I got the solution down here.
Thanks for your time and replies. :-)
Sergey Alexandrovich Kryukov 20-Mar-13 1:38am    
Great.
Good luck,
—SA

1 solution

Hi,

You could extend the textbox control to give you trim funcionality when you request the textbox value.

Find all textboxes in your project and replace with your new textbox control.
 
Share this answer
 
Comments
bbirajdar 19-Mar-13 10:02am    
Good idea +5....I am wondering why microsoft does not have inbuilt the Trim() in the Text property itself...
José Amílcar Casimiro 19-Mar-13 18:11pm    
thank you
ShivangDesai 20-Mar-13 0:44am    
It would have been great if Microsoft provided Trim().. ;-)
bbirajdar 20-Mar-13 2:46am    
Yes. There should be a default trim() inside the text property itself. So that we can have a alternative NoTrim() when not required..... I guess not more then one in more then ten thousand cases
CHill60 19-Mar-13 10:33am    
My 5 too ... sometimes the simplest ideas really are the best

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900