LostFocus in text box in asp

Hi, I am currently developing a web application in ASP.net. I create a registration form where, when a user enters the username that they would like to use, he checks the database to see if the username exists. I do not want this to be done in the event with the changed text, because I do not want it to try to query the database every time a character is entered in the text field. When I want to do this when the text fields lose focus, either by clicking on the next field or by clicking on another field, it checks the database for the username. If the username is already completed, a message similar to the prompt is placed on the side of the field.

How can I perform this action when the text field loses focus.

0
source share
2 answers

To call the client side method, you need to do the following:

1- Create a server side method:

void DoSomething(...) { ... } 

2- Deploy System.Web.UI.IPostBackEventHandler.RaisePostBackEvent , which takes one string argument (you can name the value of this argument) .:

 public void RaisePostBackEvent(string eventArgument) { DoSomething(...); } 

3- Write a script to invoke the response entry:

 function TriggerPostBack(control, arg){ __doPostBack(control, arg); } 

4 If necessary, call the PostBack launch function:

 <asp:TextBox .... onblur="TriggerPostBack('textBox', document.getElementById('txtUsername').value)" .. /> 
+5
source

onblur is the event you are looking for. See this example .

+2
source

All Articles