Regarding Page_ClientValidate() function

G

Guest

Hi,
How can we identify due to which validator control the
Page_ClientValidate() method is returning false.

why iam asking this coz in my page iam using lotz of regular expression
validators and on the click of button if iam checking whatz the return value
of Page_ClientValidate() function iam getting false.

Now on click of a checkbox i disables a couple of textboxes. i attached
regular expression validators to these textboxes. if these textboxes are
enabled and contains proper data then also Page_ClientValidate() function
returns false. even i wont get any message from the validators. if i clicked
on the checkbox and disable the textboxes then Page_ClientValidate()
function returns true.

can anybody tell me whatz really wrong...

waiting for the reply.
 
B

Brock Allen

You can iterate over the Page.Validators collection manually and check IsValid
to identify which one(s) are failing.
 
Joined
Jun 22, 2007
Messages
1
Reaction score
0
Page_ClientValidate Validation check

This can be achieved easily by having diffferent controls(Button, checkbox, etc.) set their ValidationGroup property set to some value. Match this with the ValidationGroup property of the Validators(CustomValidator, RequireFieldValidator, etc.) Next, write your javascript functions to do something on different events of the control(OnClick, etc.) and add the 'Page_ClientValidate' check to see if the validations(Custom, RequireField) are complete in the page. Example below, will display confirm message for btn1 click, if validations associated with it are complete, and NOT btn2 validations. You can also use Page_ClientValidate(' '); with empty string, if you want to check for the controls validations with no ValidationGroup assigned.

function btnOnClick(){
var validated = Page_ClientValidate('group1');
if (validated){
return confirm('Are you sure you want...');
}
}

<asp:Button ID="btn1" runat="server" ClickOnce="true" Text="ClickMe" CausesPostback="true" CausesValidation="true" ValidationGroup="group1" OnClientClick = "return btnOnClick();"/>

<asp:Button ID="btn2" runat="server" ClickOnce="true" Text="ClickMe" CausesPostback="true" CausesValidation="true" ValidationGroup="group2" OnClientClick = "return btnOnClick();"/>

Happy Programming!
 
Last edited:

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top