Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2010-11-25
7
Medium Priority
?
400 Views
Last Modified: 2012-05-10
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

0
Comment
Question by:maartendierckxsens
  • 3
  • 3
7 Comments
 
LVL 29

Expert Comment

by:Kumaraswamy R
ID: 34211439
set the                 TabIndex =0
0
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 200 total points
ID: 34211452
You should be able to force the validation by adding the following attribute to the textbox:

onblur="ValidatorOnChange(event);"
0
 

Author Comment

by:maartendierckxsens
ID: 34212171
Is it possible to provide me with some examples?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 52

Assisted Solution

by:Carl Tawn
Carl Tawn earned 200 total points
ID: 34212182
<asp:TextBox ID="txtNo" runat="server" Columns="32" MaxLength="20" onblur="ValidatorOnChange(event);"  />

Open in new window

0
 

Author Comment

by:maartendierckxsens
ID: 34212272
Can i use the protected void txtNo_LostFocus(object sender, EventArgs e)?
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 34212283
You could, but that would require an unecessary postback to the server.
0
 

Author Comment

by:maartendierckxsens
ID: 34212571
ok, i used the onblur event and it worked great.


thanks a lot
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

927 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question