Solved

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

Posted on 2010-11-25
7
381 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Login 17 40
User Authentication using Digital Certificate 2 27
designing in object programming 12 52
Output Caching in IIS 2 12
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

863 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

25 Experts available now in Live!

Get 1:1 Help Now