maartendierckxsens
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#.
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>
set the TabIndex =0
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Is it possible to provide me with some examples?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Can i use the protected void txtNo_LostFocus(object sender, EventArgs e)?
You could, but that would require an unecessary postback to the server.
ASKER
ok, i used the onblur event and it worked great.
thanks a lot
thanks a lot