I am developing a sandboxed feature for 2013 that includes several custom aspx pages, each with its own sandboxed web part through the SPUserCodeWebPart control. This project has had a long and winding history. We were originally going with a provider hosted add-in, but IT here could not get their act together to provide the trust relationship. I've abandoned that approach in favour of this one. The web parts house forms and the pages are called by custom ribbon actions. I can get it working beautifully on the server side, but none of the usual client side form validation works. The JS for web form validation is not emitted at all unless I add validators directly to the page, outside the web part control. This does not work obviously. You can't access outside controls from within a sandboxed web part. I have searched on this and found no other examples of people having this problem. Can I really be the only one? It would be really helpful to be able to get the web part to cause the page to emit the necessary javascript. The alternative is to hand code all of the client side validation, which admittedly is not a huge effort. I just think this is something that really ought to work, though I'll accept if it can't. Has anyone managed to solve this? Many thanks. Examples of aspx and ascx for visual web part shown below:
ascx¬
<%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
<%@ Assembly Name="Microsoft.Web.CommandUI, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ 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" %>
<%@ Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="SomeCustomAction.ascx.cs" Inherits="MyFakePackage.WebParts.SomeCustomAction.WebPart1" %>
<asp:Label ID="notificationLabel" runat="server" Text=""></asp:Label>
<asp:ValidationSummary ID="validationSummary" runat="server" ShowSummary="true" ShowMessageBox="true" ForeColor="Red" Font-Size="Large" EnableClientScript="true" HeaderText="Please correct any errors below." />
<asp:Table runat="server">
<asp:TableRow>
<asp:TableCell>
<asp:Label AssociatedControlID="textField" runat="server">Text Field</asp:Label>
</asp:TableCell>
<asp:TableCell>
<asp:TextBox ID="textField" runat="server" CssClass="rightFloat"></asp:TextBox>
<span> </span><asp:RequiredFieldValidator ID="rfTextField" runat="server" ControlToValidate="textField" ForeColor="Red" Text="Text Field cannot be blank" EnableClientScript="true"></asp:RequiredFieldValidator>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>
<asp:Label AssociatedControlID="dropDown" runat="server">Drop Down</asp:Label>
</asp:TableCell>
<asp:TableCell>
<asp:DropDownList ID="dropDown" runat="server" CssClass="rightFloat">
</asp:DropDownList>
</asp:TableCell>
</asp:TableRow>
</asp:Table>
<div id="submitContainer">
<asp:Button ID="submitButton" runat="server" Text="Save" OnClick="SubmitButton_Click" />
</div>
aspx ¬
<%@ Page Language="C#"
MasterPageFile="~masterurl/default.master" Inherits="Microsoft.SharePoint.WebPartPages.WebPartPage,Microsoft.SharePoint,Version=14.0.0.0,Culture=neutral,PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages"
Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<asp:Content ContentPlaceHolderID="PlaceHolderPageTitle" runat="server">
Some Custom Ribbon Action
</asp:Content>
<asp:Content ContentPlaceHolderID="PlaceHolderPageTitleInTitleArea" runat="server">
Some Custom Ribbon Action
</asp:Content>
<asp:Content ContentPlaceHolderID="PlaceHolderAdditionalPageHead" runat="server">
<style type="text/css">
body #s4-leftpanel, body #s4-ribbonrow {
display: none;
}
.s4-ca {
margin-left: 0px;
}
</style>
</asp:Content>
<asp:Content ContentPlaceHolderID="PlaceHolderLeftNavBar" runat="server"></asp:Content>
<asp:Content ContentPlaceHolderID="PlaceHolderMain" runat="server">
<WebPartPages:SPUserCodeWebPart
runat="server"
Description="Admin"
Title="Admin"
AssemblyFullName="$SharePoint.Project.AssemblyFullName$"
SolutionId="aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa" <- not the real GUID
ID="adminwp"
TypeFullName="MyFakePackage.WebParts.SomeCustomAction.WebPart1">
</WebPartPages:SPUserCodeWebPart>
</asp:Content>