Question: I would like to know, i set input text box to 00000000 and prompt chart to space. The problem is it still causes space to be between such as it allows 123 567. How to avoid these spaces

Answer: 
for windows application,   

Handle the KeyPress event for this textBox and put a single condition like.

```
if (textBox1.Text.Length==0 && e.KeyChar==' ')
{
     e.Handled = true;
}
else
{
     e.Handled = false;
}

```

for web application,   

use javascript function like

```
<asp:TextBox ID="txtPassword" TextMode="Password" runat="server" onkeypress="return DisableSpace()" ></asp:TextBox>

```

```
 <script type="text/javascript">
      function DisableSpace() {
          if (event.keyCode == 32) {
              event.returnValue = false;
              return false;
          }
      }
  </script>

```
You can handle the `KeyPress` event like this:

```
private void maskedTextBox1_KeyPress(object sender, KeyPressEventArgs e)
{
    if (e.KeyChar == ' ') e.KeyChar = (char)0;
}

```

To handle the `Keypress` event you can go to the properties,select `Events` and double click the `KeyPress` event. Or you can add this to your form constructor:

```
public Form1()
{
    InitializeComponent();
    this.maskedTextBox1.KeyPress += new KeyPressEventHandler(maskedTextBox1_KeyPress);
}

```