Sunday 15 January 2012

javascript - jquery "return false" not working properly inside update panel -


I used jquery to validate a text box inside the update panel
 

Code> $ ("[ID * = 'BTN Cret']"). Live ('click', function () {var regex = new RegExp ("^ [a-zA-Z0-9] + $"); if (! Regex.test ($ ("[Id * = 'txtbxTemplateName'] ") Val ()) {Alert ('hit'); $ (" [id * = 'lblError'] "). Text () = 'Template name is invalid!'; Details is false;}});

The click event function is being called, but still after returning it is still killing the code

Please help me on this. The reason behind this is that the default action of the button is not being prevented.

The return code is never received due to any error:

  $ ("[id * = 'lblError']"). Text () = 'The template name is invalid!'; The description is false;   

should be

  $ ("[id * = 'lbl error']") Text ('template name is invalid!'); Details are false;   

You have just disclosed, however, why return false is a bad way to stop the default action of an event. This is bad because any error in the error handler will mean that the default action is not being prevented because returned the last in the handler The description is.

If you use, then all the beautiful things will be like the main thing among them is that you can put the statement in the handler first:

  $ ( "[Id * = 'btnCreate']). Live ('click', function {var regex = new RegExp ("^ [a-zA-Z0-9] + $"); if (! Regex.test ($ ("[id * = 'txtbxTemplateName' ] ". Val ())} {event .preventDefault (); Alert ('hit'); $ (" [id * = 'lblError'] "). Text ('Template name is invalid!')}} );    

No comments:

Post a Comment