javascript - What is the correct way to call a validation Jscript function when there is a DB call? -


sorry if title doesn't explain much.

i have page textbox, button , error message.

i need validate if text entered in textbox not null or empty, has length, there no weird characters in , last not least, username doesn't exists in database. part done , working.

my question is, what's best way call jscript function validate asp:textbox username type.

right see 3 different ways.

  1. using .blur call when focus lost on textbox

  2. using .keyup or .keydown call whenever key pressed

  3. using timer validate every x seconds

now problem .blur doesn't validate without loosing focus on thing worth of focus on page. problem .keyup , .keydown call db way many times. , problem timer i'm not sure if there problem timer, why i'm asking.

i have validation server side cannot go throught.

for more information, here jscript .blur have right now.

<script type="text/javascript"> var name; var namevalid = false;  $(document).ready(function () {     name = $("#txtbox");     validatename();     name.blur(function () {         validatename();     });  });  function validatename() {     namevalid = false;     pagemethods.namevalidmethod(name.val(), successname, error); }; 

what best way it?

edit: add more information. right page textbox , button. in future when update website i'll have more textbox in page.

for short forms, best user experience perform validation upon submission of form. opposed having button and/or relying on user hit 'enter' key?

then following validation done javascript on submission of form: "if text entered in textbox not null or empty, has length, there no weird characters in it"

then if of pass, continue submission server check uniqueness of username.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -