I am facing difficulity of having to Trim Spaces in Textbox.I am given a task of needing to trim spaces in the textbox and not to allow space at the front and at the back of the textbox as when u enter a space in front of the textbox it will be a totally different data from the one which has no space. So can anyone help me about the trim in Asp.net 2.0 c# languague.
<trclass="i4">
<tdclass="i5">
<span><span><spanclass="i6">C</span>USTCODE</span><spanclass="i6">
</span>
</span>
</td>
<tdclass="i7">
<asp:RequiredFieldValidatorID="RequiredFieldValidator2"runat="server"ControlToValidate="CUSTCODETextBox"
ErrorMessage="*"Font-Bold="False"></asp:RequiredFieldValidator></td>
<tdcolspan="2"class="i8">
<asp:TextBoxID="CUSTCODETextBox"runat="server"Text='<%# Bind("CUSTCODE") %>'MaxLength="20"></asp:TextBox></td>
<tdrowspan="10"class="i9"></td>
When you are saving the data in your code behind, you can trim the text using this code:
string customerCode = CUSTOMCODETextBox.Text.Trim();
That will get you the value entered by the user, without any leading or trailing spaces.
0 comments:
Post a Comment