Donot allow any space in textbox [Resolved]

Posted by Kundan under VB.NET on 7/28/2013 | Points: 10 | Views : 4514 | Status : [Member] | Replies : 4
Suppose iam entering some integer values in textbox .It will not allow any space in the textbox.


Thanks in advance




Responses

Posted by: Satyapriyanayak on: 7/28/2013 [Member] [MVP] Silver | Points: 50

Up
0
Down

Resolved
Public Class Form1


Private Sub TextBox1_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If e.KeyChar = " " Then
e.Handled = True
End If
End Sub
End Class


If this post helps you mark it as answer
Thanks

Kundan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ssj_Kumar on: 7/28/2013 [Member] Starter | Points: 25

Up
0
Down
try with
string.IsNullOrWhiteSpace(TextBox1.Text)
Do this is TextBox.TextChanged Event.


Regards,
Jayakumar Selvakani

Kundan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jitendrasoft09 on: 7/28/2013 [Member] [MVP] Starter | Points: 25

Up
0
Down
Hi Kundan

Look into below code for not allowing space on TextBox.


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script language="javascript" type="text/javascript">
function RestrictSpace() {
if (event.keyCode == 32) {
event.returnValue = false;
return false;
}
}
</script>
<body>
<form id="form1" runat="server">
<asp:TextBox ID="TextBox2" runat="server" onkeypress="return RestrictSpace()"></asp:TextBox>
</form>
</body>
</html>


Hope you have understood.

Jitendra Kumar
If my post helps you, plz mark as an answer.

Kundan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Kundan on: 7/28/2013 [Member] Starter | Points: 25

Up
0
Down
Hi Jitendra,

It is a windows application.

Hi Ssj,

It is showing error as

IsNullOrWhiteSpace is not a member of string




Kundan, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response