LalitBarik
LalitBarik

Reputation: 193

Validate data when textbox loses focus

In my ASP.Net web application, there is a textbox to receive ProductId. When the user enters data into the ProductId textbox and moves to the next textbox, I want to validate the data against a table and if matching record is found, I want to display Product details in different controls (readonly and normal textboxes) else I want to display a message about "New Product" and continue. I do not want to do the verification AFTER the user enters all data and press the Save button, but it should be done immediately. I was hoping that the Web Form textbox would have a LostFocus event, but do not know how to handle the requirement.

Upvotes: 0

Views: 5175

Answers (2)

Gregor Primar
Gregor Primar

Reputation: 6805

It's easy solution, read this article:

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.customvalidator.servervalidate.aspx

You just need to preform javascript call to trigger server validation, use event onlostfocus.

Upvotes: 0

Prescott
Prescott

Reputation: 7412

ASP.NET Validators don't have an ajax style immediate check.

  1. Attach a custom validator to your textbox that hooks up to a validation method server side.
  2. Using javascript, you'll need to hook up an eventhandler to the focusout event and make an ajax call. That call will send the value back to the server and get a response of valid or not.

This site : http://brian.dobberteen.com/code/jquery_ajax_custom_validator/ will help you with a lot of it, but one thing is this will fire only when the page is submitted. You'll want to hook up an additional event handler to your textbox to call the validation method on focusout

Upvotes: 1

Related Questions