Why won't my form post back after validation?
Asked Answered
E

1

9

I have an asp.net page with multiple validation summaries setup with ShowMessageBox="True" and several validators. I have run into a situation where when validation fails the validation summary displays correctly but then the next click that would normally trigger a postback of the page does not trigger a postback. So the steps look like this:

  1. Click button that triggers validation.
  2. Validation fails and a messagebox with the failure message is displayed.
  3. Click a different button which does not validate but should trigger a postback nothing happens
  4. Click same button as step 3 again postback happens as expected.

What could cause this behavior?

EDIT: The validation was being done in the following manner. In the asp page:

<asp:Button runat="server" id="btn" onClientClick="return DoValidation();" />

In the javascript:

function DoValidation() {
    if (!Page_ClientValidate('group1'))
        return false;
    if (!Page_ClientValidate('group2'))
        return false;

    return true;
}
Elene answered 14/10, 2011 at 15:4 Comment(3)
you'll probably need to post some code in order to get a good answer.Brittain
try setting causesvalidation property to false for the second button?Davy
I did try setting it to false and got the same result. The page is fairly complex I was hoping someone might have seen a similar situation.Elene
E
19

After working on this and making careful use of the debugger I finally found out that when you do validation the way described in the edit to the question a boolean is set on failure that blocks the next PostBack of the page from going through. I believe this is done when validation is being done automatically instead of explicitly as I'm doing here. Changing the javascript described above to look like this:

function DoValidation() {
    if (!Page_ClientValidate('group1')) {
        Page_BlockSubmit = false;
        return false;
    }
    if (!Page_ClientValidate('group2')) {
        Page_BlockSubmit = false;
        return false;
    }

    return true;
}

Causes the problem to go away. Hopefully this will help the next person who makes the same mistake I did.

Elene answered 24/10, 2011 at 19:23 Comment(3)
Debugger time saved for me. Thanks!Ciliata
I wish I saw your answer an hour ago!Callup
Glad I found this!Lancers

© 2022 - 2024 — McMap. All rights reserved.