Solved

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

Posted on 2010-11-25
7
380 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
Comment Utility
set the                 TabIndex =0
0
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 50 total points
Comment Utility
You should be able to force the validation by adding the following attribute to the textbox:

onblur="ValidatorOnChange(event);"
0
 

Author Comment

by:maartendierckxsens
Comment Utility
Is it possible to provide me with some examples?
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 52

Assisted Solution

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

Open in new window

0
 

Author Comment

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

Expert Comment

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

Author Comment

by:maartendierckxsens
Comment Utility
ok, i used the onblur event and it worked great.


thanks a lot
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Default parameter problem in C# 3 25
Problem to open Excel file 15 37
ConsoleSql 1 12
Achieve json result 2 28
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now