Click here to Skip to main content
15,949,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In the following code I want to stop the proceeds if someone enters 'space' as a first character.
If the first character is a space, is it possible to assign the value to variable v_MyAddressStreet as "" (blank).
I dont want to use 'Required field validation'

C#
protected void TextBox10_TextChanged(object sender, EventArgs e)   // MyAddress Street
   {

       v_MyAddressStreet = TextBox10.Text;
       if (v_MyAddressStreet == "")
       {
           RBL7clear();
       }
   }
Posted

If you mean "I want to know if the string is blank or empty, then there is thew IsNullOrWhiteSpace method:
C#
protected void TextBox10_TextChanged(object sender, EventArgs e)   // MyAddress Street
   {
       v_MyAddressStreet = TextBox10.Text;
       if (string.IsNullOrWhiteSpace(v_MyAddressStreet))
       {
           RBL7clear();
       }
   }
If the field is null, empty, or just contains spaces the RBL7clear method will be called.
 
Share this answer
 
Comments
S.Rajendran from Coimbatore 23-Nov-13 7:18am    
I am using VS2008. 'IsNullOrWhiteSpace' is not available. Only 'IsNullOrEmpty' is available.
OriginalGriff 23-Nov-13 7:27am    
You need to tell us these things! :laugh:
Ok, so use IsNullOrEmpty, but use Trim on the textbox first:
v_MyAddressStreet = TextBox10.Text.Trim();
That removes any whitespace for the beginning and the end.
I think if you just check v_MyAddressStreet.StartsWith(" "), that will do the trick for you here.It will check if the first character is space or not. Follow this one also:
How to stop the first character in a text box from being space?[^]
 
Share this answer
 
v3
Comments
S.Rajendran from Coimbatore 23-Nov-13 7:40am    
Thanks. It works.
ridoy 23-Nov-13 7:42am    
Glad to help you,:)
C#
protected void TextBox10_TextChanged(object sender, EventArgs e)   // MyAddress Street
   {
if(TextBox10.Text!="")
{


       
           RBL7clear();
      
}
else 
{
//show your message
}
   }
 
Share this answer
 
v2
Comments
OriginalGriff 23-Nov-13 7:25am    
Reason for my vote of one:
if (a!=b)
if (a==b)
... statement here cannot be executed ...

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