asp.netvalidationvalidationgroup

ASP.NET 3.5 validation groups not working


I wish I could paste in my markup, but it's too complex and contains a lot of references to the client's company name. I am hoping someone with vast experience might be able to point me in the right direction.

We have a master page with a ValidationSummary that is not part of a validation group. On our content page, we have another ValidationSummary that is assigned to a validation group called ValReject. On the content page is also a CustomValidator that uses ClientValidationFunction and a button, both of which are also assigned to ValReject.

When I click the button, the client function executes once, but the error reports to both validation summaries, the one on the content page and the on on the master page. I even added a third validation summary and set its group to something like "asdf", but it gets reported to, as well, meaning all three validation summaries are showing the same error on the page.

I then created a separate ASP.NET test project, pasted all the code in, and ran it and it validates like it should.

I then played around with AutoEventWireup on the content page. When I set it to false, validation works, but the page load event doesn't fire. What's up with that?

I know you probably need code samples, but, like I said, I just can't do that without going through a huge headache (trust me, the master and content page markup is huge.

The question here is: Does anyone have an idea of what could cause a single validator to report to ALL validation summaries on the page even though only one of them shares the same validation group as the validator and button?

edit: When I pasted the markup into my test app, I did have to remove some tags to get it to work since the test app doesn't have references to some assemblies used by the real master page. Some things I removed are:

<%@ Register Assembly="RadMenu.Net2" Namespace="Telerik.WebControls" TagPrefix="radM" %>

<radM:RadMenu ID="RadMenu1" runat="server" DataSourceID="smdsMenu" Skin="CssGrey" ClickToOpen="True" EnableViewState="False" CausesValidation="false" />

So the fact that it works on my test app leads me to the conclusion that we're doing something on our production app that I am not doing in my test app. Yes, I know this is vague, but perhaps a light bulb will go off in someone's head.


Solution

  • Man, after hours and hours of spinning my wheels, I finally figured it out. We use this extension method to disable double clicks of buttons:

        public static void DisableDoubleClick(this Button Control)
        {
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
    
            sb.Append("if (typeof(Page_ClientValidate) == 'function') { ");
            sb.Append("if (Page_ClientValidate() == false) { return false; }} ");
            sb.Append("this.disabled = true;");
            sb.Append(Control.Page.ClientScript.GetPostBackEventReference(Control, ""));
            sb.Append(";");
            Control.Attributes.Add("onclick", sb.ToString());
        }
    

    This is what was messing up the validation as it was invoking global validation. I fixed this by making the following change:

            sb.Append(string.Format("if (Page_ClientValidate({0}) == false) {{ return false; }}}} ",
                Control.ValidationGroup == string.Empty ? string.Empty : string.Format("\"{0}\"", Control.ValidationGroup)));
    

    What clued me in was when I set AutoEventWireup to false to see what would happen. This kept the page load event from firing which is where the above extension method was being called. What a needle in the haystack, this problem.

    I don't blame anyone for not answering due to lack of details, but I will keep this up in case anyone else can use it.

    edit: Thanks to slfan and gbs. I had just figured out the issue and was coming back here to post my answer when I see that you two were essentially tackling my issue from both sides of the problem. The page load event is where the binding was occurring and the extension method being called was messing up the Page_ClientValidate function. Since you both are technically right and I can't award both of you the answer, I hope no one gets upset if I mark my own as the answer here. You two are definitely good at analyzing such issues with minimal details and no code samples. Props.