You can use
TrimEnd()
method for the last space char:
yourText = yourText.Trim();
yourText = yourText.TrimEnd();
OR
You can replace the spaces by
Replace()
method such as:
Text.Replace(" ", string.empty);
But more importantly you should use
FilteredTextBoxExtender
for avoiding characters such as space and the other chars that you desire not be entered by user.
For more info check
AJAX control tool kit's FilteredTextBoxExtender[
^].
Use it on invalidchars.
Good luck,
OI