0

I'm trying to create custom form authentication page for SharePoint Server based on default .aspx one:

<%@ Assembly Name = "$SharePoint.Project.AssemblyFullName$" %>
    <%@ Import Namespace = "Microsoft.SharePoint.ApplicationPages" %>
    <%@ Register TagPrefix = "SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
    <%@ Register TagPrefix = "Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
    <%@ Register TagPrefix = "asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
    <%@ Import Namespace = "Microsoft.SharePoint" %>
    <%@ Assembly Name = "Microsoft.Web.CommandUI, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
    
    <%@ Page Language = "C#" AutoEventWireup="true" CodeBehind="Login.aspx.cs" Inherits="SharePointCustomLogin.Layouts.SharePointCustomLogin.Login" MasterPageFile="errorv15.master" %>
    
    <asp:Content ContentPlaceHolderID = "PlaceHolderPageTitle" runat="server">
        Site name
        <SharePoint:EncodedLiteral runat="server" EncodeMethod="HtmlEncode" ID="ClaimsFormsPageTitle" Visible="false" />
    </asp:Content>
    <asp:Content ContentPlaceHolderID = "PlaceHolderMain2" runat="server">
        <div id = "SslWarning" style="color: red; display: none">
            <SharePoint:EncodedLiteral runat = "server" EncodeMethod="HtmlEncode" ID="ClaimsFormsPageMessage" />
        </div>
            <asp:Login class="share-point-form" ID="signInControl" FailureText="<%$Resources:wss,login_pageFailureText%>" runat="server" Width="100%">
                <LayoutTemplate>
                    <asp:Label ID = "FailureText" runat="server" />
                    <asp:TextBox ID = "UserName" autocomplete="off" runat="server" Width="99%" />
                    <asp:TextBox ID = "password" TextMode="Password" autocomplete="off" runat="server" Width="99%" />
                    <asp:Button ID = "login" CommandName="Login" Text="<%$Resources:wss,login_pagetitle%>" runat="server"/>
                    <asp:CheckBox ID = "RememberMe" runat="server" />
                </LayoutTemplate>
            </asp:Login>
    </asp:Content>

Master pages form on submit:

<form runat="server" onsubmit="if (typeof(_spFormOnSubmitWrapper) != 'undefined') {return _spFormOnSubmitWrapper();} else {return true;}">

I show error messages when fields are empty with js. The problem is that when the form is submitted, page updates and the errors messages will shortly disappear. To handle this I need to replace default onSubmit with my own, and for this I need to know how to replicate what original form onSubmit does, and what to post to SP server in particular. With that I would be able to validate data and response by displaying error messages.

Has anyone done something like this? Maybe there are another good solutions for this type of a problem.

1 Answers1

0

I found a very simple fix. Error messages disappear because of postback when form is submitted. So to fix that we need to allow form to be submitted only when validation code does not finds any errors. So I just added onClientClick to a asp:button with function:

 onClientClick="return validateFormFields();

If validate function returns false form can't be submitted = no postback = validation error messages remain in place.