0
votes

I'm using standard ASP.NET WebForms validation controls in my app. I've just noticed that at some point, client side validation seems to have stopped working as it should. The web page correctly shows the errors in red for a short while, but then still causes an unnecessary postback which causes changes to get lost.

This is a .net 4.5 project.

I have the following appSetting:

<add key="ValidationSettings:UnobtrusiveValidationMode" value="None" />

Additionally, causesValidation is set to true on the submit button and the ValidationGroup has been set to the correct value on the button and validators etc.

1

1 Answers

0
votes

To answer my own question, it was because I'd overridden the render method of the tag (because I'm using URL rewriting) and as a side effect, it wasn't rendering the onclick attribute which is normally rendered server side.

Instead I changed my custom "ActionlessForm" control to use the following code:

public class Form : System.Web.UI.HtmlControls.HtmlForm
{
    /// <summary>
    /// The RenderAttributes method adds the attributes to the rendered &lt;form&gt; tag.
    /// We override this method so that the action attribute is not emitted.
    /// </summary>
    protected override void RenderAttributes(HtmlTextWriter writer)
    {
        // You cannot simply remove the form action as it seems to get rendered anyway
        // but if you set it to the RawURL it will be the correct value on URL rewritten pages.
        base.Attributes["action"] = HttpContext.Current.Request.RawUrl;
        base.RenderAttributes(writer);
    }
}