Solved

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

Posted on 2010-11-25
7
382 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 50 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 52

Assisted Solution

by:Carl Tawn
Carl Tawn earned 50 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

777 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