Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
I have a RequiredFieldValidator applied to a TextBox.
At the same time, I set the submit button's OnClientClick property as follows:
UpdateButton.OnClientClick = "return confirm('Save the changes?');"
 
when i set onclientclick then my validator not work
Posted 6-Nov-10 19:41pm
ptvce1.1K
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

I did the same. And it was working fine.You must be doing something wrong.
 
Actually, when you set the OnClientClick property, then this code will be executed first, then if postback occurs the validation will be fired.
 
In your case, On clicking of UpdateButton, it will show the confirmation box, if user clicks OK then validation will be fired because page will try for postback and if clicked Cancel, then nothing will happen and validation will also not be fired.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

UpdateButton.OnClientClick = "return validateFun();"
// Call following function in client click event of Update Button
function validateFun() {
var rf=$get('<%= RequiredFieldValidator1.ClientID %>')
;
                if (rf != null){
            ValidatorEnable(rf, true);
                    ValidatorValidate(rf);
                    if(rf.isvalid==true){
            var answer=window.confirm('Save the changes?');
            return answer;
                      }
                     else
                     return false;
            }
         else
         return false;
}
  Permalink  
v2
Comments
pradiprenushe at 18-Jul-12 6:17am
   
good solution.
Wes Aday at 18-Jul-12 7:56am
   
Please do not resurrect ancient threads.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

You may want to try
CausesValidation="true"
on your button, UpdateButton.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Hi
You need to use Page_ClientValidate() function to invoke the page validation.
The below links will give you a more information.
 
http://stackoverflow.com/questions/8918722/onclientclick-code-preventing-validation-from-working[^]
 
http://ideaofinnovation.blogspot.in/2012/03/validation-control-not-working-after.html[^]
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 566
1 OriginalGriff 345
2 CPallini 200
3 PIEBALDconsult 150
4 Magic Wonder 131
0 OriginalGriff 5,795
1 Sergey Alexandrovich Kryukov 5,028
2 CPallini 4,700
3 George Jonsson 3,142
4 Gihan Liyanage 2,450


Advertise | Privacy | Mobile
Web02 | 2.8.140916.1 | Last Updated 18 Jul 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100