Link to home
Start Free TrialLog in
Avatar of maartendierckxsens
maartendierckxsensFlag for Belgium

asked on

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

Avatar of Kumaraswamy R
Kumaraswamy R
Flag of India image

set the                 TabIndex =0
ASKER CERTIFIED SOLUTION
Avatar of Carl Tawn
Carl Tawn
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of maartendierckxsens

ASKER

Is it possible to provide me with some examples?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Can i use the protected void txtNo_LostFocus(object sender, EventArgs e)?
You could, but that would require an unecessary postback to the server.
ok, i used the onblur event and it worked great.


thanks a lot