Friday, December 24, 2010

Validation not working if i added client script in a save button attribute property

In this scenario, I have a series of textbox controls that has required field validations and a save button with the following attribute property set in pageload event:
1:  btnSave.Attributes.Add("onclick", "return confirm  
2:  ('Proceed saving or updating this record?')");  

In most cases, this works fine, but the problem is if i clicked ok in the confirm dialog of javascript, the validation of required fields will be bypassed.

So the solution would be to modify the script to return false if cancel is pressed in the confirm dialog of javascript so that validation will work..

Here is the modified script:
 btnSave.Attributes.Add("onclick", "if(!confirm  
 ('Proceed saving or updating this record?'))  
 return false;");  

If the user will click ok, in the javascript confirm dialog, validations will be executed.

0 comments:

Post a Comment