Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Jan 23, 2013 09:00 PM by otnielpena
Jan 23, 2013 01:44 AM|LINK
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.
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.
Sub ValidateBtn_Click(sender As Object, e As EventArgs)
If (Page.IsValid) Then
lblOutput.Text = "Page is Valid!"
lblOutput.Text = "Some required fields are empty."
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.
Jan 23, 2013 02:51 AM|LINK
Did you check "CausesValidation" property?
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.
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: