Hope you can help me with a problem I'm currently having.
So I have a page with multiple updatepanels, validation groups and modals.
My problem is the validators (required) are not firing on the first postback, so the page needs to be postbacked once, before any of my validators work. After the initial postback, everything works fine.
Any thoughts on why this is?
Ps. My buttons all have the 'OnClientClick="if(Page_ClientValidate('SpecificValidationGroup')) return confirm('Are you sure you want to save the record?'); return false;"' line.
The page can force the validators to work by inserting the if page.IsValid() function in the event handler of the control which fires the postback. Also you can do it using brute force by using the validate method and passing the group name as parameter.
You can use the IsValid method individualy in each validator control.Make sure that the control that fires the postback has the CausesValidation = true, otherwise it would not ask the validators about their work.
Sub ValidateBtn_Click(sender As Object, e As EventArgs)
Page.Validate()
If (Page.IsValid) Then
lblOutput.Text = "Page is Valid!"
Else
lblOutput.Text = "Some required fields are empty."
End If
End Sub
Yes, but that would require a postback before the validators would work. Which in my case already does that.
What I would want to do is for the validators to "fire" their error messages BEFORE posting back and even before the JS confirmbox is fired as it looks more natural.
Note that after posting back once, what I want to happen works perfectly, it's just wierd that it has to postback once before working.
Yup. It's not really a problem of the fields validating or not, the problem I want to address is removing the need for the "first" postback my page needs to be able to run how I want it to.
You need to check if the validators have the EnableClientScript property enabled. That is the property that makes them work in the client side before posting back to the server. Check the following link from Microsoft:
jessesy
0 Points
3 Posts
Problem with multiple asp validators
Jan 23, 2013 01:44 AM|LINK
Hi all.
Hope you can help me with a problem I'm currently having.
So I have a page with multiple updatepanels, validation groups and modals.
My problem is the validators (required) are not firing on the first postback, so the page needs to be postbacked once, before any of my validators work. After the initial postback, everything works fine.
Any thoughts on why this is?
Ps. My buttons all have the 'OnClientClick="if(Page_ClientValidate('SpecificValidationGroup')) return confirm('Are you sure you want to save the record?'); return false;"' line.
otnielpena
Member
210 Points
38 Posts
Re: Problem with multiple asp validators
Jan 23, 2013 01:55 AM|LINK
The page can force the validators to work by inserting the if page.IsValid() function in the event handler of the control which fires the postback. Also you can do it using brute force by using the validate method and passing the group name as parameter. You can use the IsValid method individualy in each validator control.Make sure that the control that fires the postback has the CausesValidation = true, otherwise it would not ask the validators about their work.
http://msdn.microsoft.com/en-us/library/vstudio/system.web.ui.page.isvalid(v=vs.100).aspx
http://msdn.microsoft.com/en-us/library/0ke7bxeh.aspx
Sub ValidateBtn_Click(sender As Object, e As EventArgs) Page.Validate() If (Page.IsValid) Then lblOutput.Text = "Page is Valid!" Else lblOutput.Text = "Some required fields are empty." End If End Subjessesy
0 Points
3 Posts
Re: Problem with multiple asp validators
Jan 23, 2013 02:06 AM|LINK
Yes, but that would require a postback before the validators would work. Which in my case already does that.
What I would want to do is for the validators to "fire" their error messages BEFORE posting back and even before the JS confirmbox is fired as it looks more natural.
Note that after posting back once, what I want to happen works perfectly, it's just wierd that it has to postback once before working.
cnranasinghe
Star
8899 Points
1800 Posts
Re: Problem with multiple asp validators
Jan 23, 2013 02:51 AM|LINK
Did you check "CausesValidation" property?
jessesy
0 Points
3 Posts
Re: Problem with multiple asp validators
Jan 23, 2013 03:05 AM|LINK
Yup. It's not really a problem of the fields validating or not, the problem I want to address is removing the need for the "first" postback my page needs to be able to run how I want it to.
otnielpena
Member
210 Points
38 Posts
Re: Problem with multiple asp validators
Jan 23, 2013 09:00 PM|LINK
You need to check if the validators have the EnableClientScript property enabled. That is the property that makes them work in the client side before posting back to the server. Check the following link from Microsoft:
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.basevalidator.enableclientscript(v=vs.100).aspx