Donate

Validation In ASP.NET WebForm Not Working For Confirm Dialog

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:
  btnSave.Attributes.Add("onclick", "return confirm  
  ('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.

Comments

Donate

Popular Posts From This Blog

WPF CRUD Application Using DataGrid, MVVM Pattern, Entity Framework, And C#.NET

TypeScript Error Or Bug: The term 'tsc' is not recognized as the name of a cmdlet, function, script file, or operable program.

Invalid nested tag div found, expected closing tag input