How to display an error when textbox web control has lost focus?

I have a textbox & button on my web page. When the page is loaded, the textbox gets the focus. When I click the button and nothing is entered in the textbox, an error message is raised. I want to do the same when the textbox loses focus. How can it be done so that when the textbox loses focus, the error message is raised?

The error is raised using a requiredfield validator and the language used is C#.
*.aspx
------
<asp:TextBox ID="txtNo" runat="server" Columns="32" MaxLength="20"></asp:TextBox>

<asp:RequiredFieldValidator ID="reqFieldNo" ControlToValidate="txtNo" 
    Display="Static" runat="server" SetFocusOnError="True" 
    ErrorMessage="Assign a number to the project."><img src="images/png/error5.png" alt="Assign a number to the project" width="20" height="20" /></asp:RequiredFieldValidator>

Open in new window

maartendierckxsensAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Carl TawnConnect With a Mentor Systems and Integration DeveloperCommented:
You should be able to force the validation by adding the following attribute to the textbox:

onblur="ValidatorOnChange(event);"
0
 
Kumaraswamy RCommented:
set the                 TabIndex =0
0
 
maartendierckxsensAuthor Commented:
Is it possible to provide me with some examples?
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
Carl TawnConnect With a Mentor Systems and Integration DeveloperCommented:
<asp:TextBox ID="txtNo" runat="server" Columns="32" MaxLength="20" onblur="ValidatorOnChange(event);"  />

Open in new window

0
 
maartendierckxsensAuthor Commented:
Can i use the protected void txtNo_LostFocus(object sender, EventArgs e)?
0
 
Carl TawnSystems and Integration DeveloperCommented:
You could, but that would require an unecessary postback to the server.
0
 
maartendierckxsensAuthor Commented:
ok, i used the onblur event and it worked great.


thanks a lot
0
All Courses

From novice to tech pro — start learning today.