Click here to Skip to main content
15,896,153 members
Please Sign up or sign in to vote.
3.67/5 (2 votes)
See more:
i design a webpage that have textbox,
when user want type space it's not accpet,
thanks
this is my code:
ASP.NET
 <table align="center" cellspacing="5px" class="tbl-inside-form">
        <tr>
            <td>
                name
            </td>
            <td>
                <div class="frame-white-right">
                </div>
                <div class="frame-white-body form-txt-body">
                    <asp:TextBox ID="name" Text="" runat="server"></asp:TextBox>
                </div>
                <div class="frame-white-left">
                </div>
            </td>
        </tr>
        <tr>
            <td>
family
            </td>
            <td>
                <div class="frame-white-right">
                </div>
                <div class="frame-white-body form-txt-body">
                    <asp:TextBox ID="family" Text="" runat="server"></asp:TextBox>
                </div>
                <div class="frame-white-left">
                </div>
            </td>
        </tr>
        <tr>
            <td>
                tell
            </td>
            <td>
                <div class="frame-white-right">
                </div>
                <div class="frame-white-body form-txt-body">
                   <asp:TextBox ID="tel_no" Text="" runat="server"></asp:TextBox>
                </div>
                <div class="frame-white-left">
                </div>
            </td>
        </tr>
         <tr>
            <td>
                email
            </td>
            <td>
                <div class="frame-white-right">
                </div>
                <div class="frame-white-body form-txt-body">
                    <asp:TextBox ID="email" Text="" runat="server"></asp:TextBox>
                </div>
                <div class="frame-white-left">
                </div>
            </td>
        </tr>
        <tr>
            <td>
                comment
            </td>
            <td>
                <asp:TextBox ID="description" Text="" CssClass="text-area-form" runat="server" TextMode="MultiLine"></asp:TextBox>
            </td>
        </tr>
        <tr>
            
            <td colspan="2">
                <div class="frame-btn-left">
                            </div>
                            <div class="frame-btn-body">
                                <asp:Button ID="btn_submit" runat="server" Text="ثبت" onclick="btn_submit_Click" />
                            </div>
                            <div class="frame-btn-right">
                            </div>
            </td>
        </tr>
    </table>
Posted
Updated 19-Sep-13 7:47am
v4

You need to use RegularExpressionValidator for this purpose.See this solution:
validation on textbox (no space)[^]
 
Share this answer
 
Comments
ridoy 19-Sep-13 15:44pm    
downvoter,please leave a comment here so that answers could be improved which will help OP,possibly CP isn't a place for only voting purpose!
Please See this link which may help you
How to avoid sapce in textbox
 
Share this answer
 
you may use this...

C#
void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
     if ((sender as TextBox).SelectionStart == 0)
          e.Handled = (e.KeyChar == (char)Keys.Space);
     else
          e.Handled = false;
}
 
Share this answer
 

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