Click here to Skip to main content
15,894,343 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
how i can validate that textbox should not be blank using text changed event??
Posted

You can take the help of RequiredFieldValidater validation control for checking blank textbox(textbox should not be blank).

XML
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1"runat="server" ControlToValidate="TextBox1" Display="Dynamic" ErrorMessage="should not be blank !!"></asp:RequiredFieldValidator>
 
Share this answer
 
v3
with events you should set AutoPostBack to True then use this event :
C#
protected void btnSubmitForm_Click(object sender, EventArgs e)
{
   if(textbox1.Text=="")
  {
    //do anything you want
  }
}

then check if it is blank ...


you can use this too :
ASP.NET
<asp:requiredfieldvalidator id="RequiredFieldValidator1" runat="server" controltovalidate="txtName" xmlns:asp="#unknown">
ErrorMessage="Enter your name!" 
ForeColor="Red">
</asp:requiredfieldvalidator>
 
Share this answer
 
you can use javascript on onblur event to validate textbox on 'ontextchanged' event
for details use following link:
textbox focus out validation using custom validator[^]
 
Share this answer
 
Generally your required field validator will take care of that. But in case if you want serverside validation for that, then try this:
C#
if(textbox1.Text.Trim() != ""){
    //Show error message
}
else{
   //Success.
}




--Amit
 
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