How to add custom user control in SharePoint 2013 HTML master page - sharepoint

I am trying to add custom usercontrol in SharePoint 2013 HTML master page, but its not working and showing the message
SharePoint can't parse this file, most likely because of an incorrectly formatted SharePoint snippet. The markup at the following location is causing problems. Edit the markup manually to fix it, or replace it with a new snippet from the Snippet Gallery.
Invalid SharePoint markup at line 145. Please repair or recreate the markup
following is the code snippet for HTML master page.
<!--CS: Start Create Snippets From Custom ASP.NET Markup Snippet-->
<!--SPM:<%# Register Src="~/_controltemplates/15/SharePointProject1/UserControl1.ascx" TagPrefix="uc1" TagName="MyDepartmentControl" %>-->
<!--SPM:<uc1:MyDepartmentControl runat="server" id="MyDepartmentControl1" />-->
<!--CE: End Create Snippets From Custom ASP.NET Markup Snippet-->
Please help me how i can make it possible to add asp.net user-control in SharePoint 2013 HTML Master page.
Thanks in advance.

I just solved this problem.
The answer is; convert this line
<!--SPM:<%# Register Src="~/_controltemplates/15/SharePointProject1/UserControl1.ascx" TagPrefix="uc1" TagName="MyDepartmentControl" %>-->
to
<!--SPM:<%# Register TagPrefix="uc1" TagName="MyDepartmentControl" Src="~/_controltemplates/15/SharePointProject1/UserControl1.ascx" %>-->
Have fun..

Related

SharePoint Link with QueryString Parameters

The task is to migrate classic ASP functionality to SharePoint Server 2013.
On the ASP page, a certain link is visible only if the authenticated user's password can be retrieved from a database. The link looks similar to:
<a target="_blank" href="https://www.someurl.com/secure/login.php?username=<%=strUserName%>&password=<%=rsOpenOrders("CL_password")%>" onmouseover="self.status=' '; return true;">
<img border="0" src="somelogo.gif" width="267" height="80" /></a>
I'm new to SharePoint, and I would appreciate your help (conceptual and code snippet) in solving this problem.
I understand that writing "code behind" is not highly encouraged with SharePoint pages and web parts.
So, what's the best alternative to be able to use the authenticated username value in building the first querystring parameter, and to query a SQLServer database to retrieve the value for the second querystring parameter? Please ignore the security concern here. Thanks!
its called SPSecurityTrimmedControl
example:
<%# Register TagPrefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<SharePoint:SPSecurityTrimmedControl ID="SPSecurityTrimmedControl1" runat="server"
AuthenticationRestrictions="AuthenticatedUsersOnly" Permissions="ManageWeb" PermissionContext="CurrentSite">
<INCLUDE OUR CONTROL / CONTENT HERE>
</SharePoint:SPSecurityTrimmedControl>
I ended up creating custom web parts developed using Visual Studio 2013 for each particular link that needed query string parameters to be built based on values retrieved from database.

Apply Web Part Connections to web parts on the ascx page of other web parts

I have created a visual web part that combines two other previously created web parts into one nicely styled web part. This is done simply by adding Register tags to the ascx page of the web part, and then adding the web part tags just as I would on a page layout, like so:
WebPart_ParentAssignmentsUserControl.ascx:
<%# Register tagprefix="WebParts" namespace="Microsoft.SharePointLearningKit.WebParts" assembly="Microsoft.SharePointLearningKit, Version=1.3.1.0, Culture=neutral, PublicKeyToken=24e5ae139825747e" %>
<%# Register tagprefix="MyChildrenWebPart" namespace="MLG2010.WebParts.MyChildren.MyChildrenWebPart" assembly="MLG2010.WebParts.MyChildren, Version=1.0.0.0, Culture=neutral, PublicKeyToken=9f4da00116c38ec5" %>
<WebParts:AssignmentListWebPart runat="server" ListScope="false" AllowEdit="True" AllowConnect="True" Title="Assignment List Web Part" IsIncluded="True" Dir="Default" SummaryWidth="150px" IsVisible="True" AllowMinimize="True" AllowHide="True" ExportControlledProperties="True" ZoneID="" ID="g_1c528b46_baf2_4cf2_a004_91f84c4f4556" FrameState="Normal" DisplaySummary="True" ExportMode="All" SuppressWebPartChrome="False" DetailLink="" HelpLink="" MissingAssembly="Cannot import this Web Part." PartImageSmall="" AllowRemove="True" ToolTip="Assignment List - Use this web part to keep track of your SharePoint Learning Kit assignments." HelpMode="Modeless" FrameType="Default" AllowZoneChange="True" PartOrder="0" Description="Display the assignments for an instructor or learner." PartImageLarge="" IsIncludedFilter="" __MarkupType="vsattributemarkup" __WebPartId="{1c528b46-baf2-4cf2-a004-91f84c4f4556}" WebPart="true" Height="" Width=""></WebParts:AssignmentListWebPart>
<MyChildrenWebPart:MyChildrenWebPart runat="server" PageSize="5" StudentsSiteURL="/student" PictureLibraryTitle="Students Picture Library" ADChildAttribute="otheripphone" Description="My WebPart" DefaultPictureURL="../../Students Picture Library/DefaultChild.jpg" ShowErrors="True" PictureLibraryUrl="../../Students Picture Library" Title="MyChildrenWebPart" ADEntryPoint="LDAP://dc=redconnect-test" __MarkupType="vsattributemarkup" __WebPartId="{d13a3729-e2b8-4436-ac1b-b75c914a3596}" WebPart="true" __designer:IsClosed="false" id="g_d13a3729_e2b8_4436_ac1b_b75c914a3596"></MyChildrenWebPart:MyChildrenWebPart>
The problem here, is that I need these two web parts to communicate via web part connections. since they are only added here on the aspx, sharepoint does not "know" about them, and thus they do not get a chrome and thus I cannot set up the web part connections in the browser.
Is there a way to set up web part connections on web parts that are added this way? Or maybe if I can just activate the chrome on these web parts?
You can define the connection statically. Note that using this way, you cannot create/modify/delete the connection using the browser.
See:
How to: Declare a Static Connection between Two Web Parts Controls
In the end, I separated the web part into the pieces that could connect normally, and then used styling to make it look as if they were one. I have not found any documentation on the consequences of putting web parts inside other web parts as i attempted.

SharePoint custom form

I am looking to create a page with a single form on it that does the following:
Contact a webservice with input from the form.
Perform an action (programmed using C#) depending on the result of the webservice call.
Since I am not interacting with any lists or similar on the SharePoint site, I was thinking a WebPart would be the simplest way to add the form and catch the submit-event, but I am not sure if this is the best practice or an easier/better way exists.
I also need to restrict access to the form to a specific usergroup.
Thanks in advance!
A new SharePoint Web Part is probably the most common way to provide this solution in SharePoint and fits your requirements well. Though your solution doesn't call for it, you do have access to the lists from custom web part code.
If you are using SharePoint 2007, Visual Studio Extensions provide the Microsoft supported way to create one easily. It's much easier with Visual Studio 2010 and SharePoint 2010.
Some other options would be an InfoPath Form with custom code or a custom application page with code behind. The benefit of the web part is that it works with all versions of SharePoint and can be added to any web part page on the site and customized by users. Also, the application page may not pick up the master page if you are on SharePoint 2007.
Use WebDAV to upload an ASPX page to a site in SharePoint. Then upload your assembly to each SharePoint server, the bin folder of your application is preferred, or add it to the GAC.
Your ASPX page might look like this:
<%# Page Language="C#" masterpagefile="~masterurl/custom.master" inherits="MyAssembly, MyClass, Version=1.0.0.0, Culture=neutral, PublicKeyToken=c48b11b32c9eb4a7" %>
<asp:Content runat="server" ContentPlaceholderID="PlaceHolderPageTitle">My Title</asp:Content>
<asp:Content runat="server" ContentPlaceholderID="PlaceHolderPageTitleInTitleArea">My Page</asp:Content>
<asp:Content runat="server" ContentPlaceholderID="PlaceHolderMain">
<asp:Button runat="server" ID="ButtonClickMe" Text="Click Me!" />
</asp:Content>
Then your assembly might look something like this:
public class MyClass : Microsoft.SharePoint.WebPartPages.WebPartPage
{
protected global::System.Web.UI.WebControls.Button ButtonClickMe;
protected override void OnLoad(EventArgs e)
{
base.OnLoad( e );
ButtonClickMe.Click += new EventHandler( ButtonClickMe_Click );
}
void ButtonClickMe_Click(object sender, EventArgs e)
{
if (!Page.IsValid)
return;
// Do stuff here
}
}
You won't be able to edit the permissions of the ASPX page directly, but you can manipulate the permissions of the site it is in (thus, restrict the site to only the usergroup which you want to access the form).

MOSS 2007 team site page title

I'm trying to display the page title (html title) on the default.aspx page of a custom site template. The template is based on a MOSS team site template.
But the html page title is rendered empty. Can I change the code in the default.aspx and/or the sites master page to define the title myself? Details of the deafult.aspx and default.master page as below: Thanks.
Default.aspx:
<asp:Content ContentPlaceHolderId="PlaceHolderPageTitle" runat="server">
<SharePoint:EncodedLiteral runat="server" text="<%$Resources:wss,multipages_homelink_text%>" EncodeMethod="HtmlEncode"/>
- <SharePoint:ProjectProperty Property="Title" runat="server"/>
</asp:Content>
default.master
<Title ID=onetidTitle><asp:ContentPlaceHolder id=PlaceHolderPageTitle runat="server"/></Title>
I'm not sure a understand your problem, but have you tried to enter your title like this in your .aspx file:
<asp:Content ContentPlaceHolderId="PlaceHolderPageTitle" runat="server">
This is my title</asp:Content>
Or am I missing something obvious here?
Do you want to do it in code?
You maybe also have stumbled upon this bug. (although it's Ajax specific)
2 additional things:
Have you checked-in, published and approved the master page?
Have you checked in the .aspx page?
If you have Sharepoint Designer, then its matter of fiew clicks to modify page title.
I checked the Master page the site was inheriting which was the site template master page. I change the title tag to display the site title using the Sharepoint ProjectProperty tag and property title.
<Title ID=onetidTitle> <asp:ContentPlaceHolder id=TSM_PlaceHolderPageTitle runat="server">Parent Site Title- <SharePoint:ProjectProperty Property="Title" runat="server"/></asp:ContentPlaceHolder></Title>

How to change the default InfoPath form server Url for a form library in SharePoint

By default MOSS directs browser enabled InfoPath forms to the /_layouts/formserver.aspx page, with the query string parameters that define the form to display or edit. We have defined our own page (for a number of reasons) and would like to direct the forms in the form library there. The page can be hosted in that same _layouts folder, in a document library, it doesn't really matter.
Seems like there should be a linkeage (hopefully in a form of a configuration setting) that tells SharePoint where to direct the forms.
Thanks!
If you are using the SharePoint lists or form libraries to display the list of forms, you could add a jquery rewrite (in either a Custom Editor Web Part or Master Page) to look for links to the FormServer.aspx link.
<script type="text/javascript" src="~/_layouts/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
//Rewrite Form Links to Open in Custom Page
$("a[href*='/_layouts/FormServer.aspx']").each(function()
{
var formFileName = this.href.figureOutWhatFormAndParamsYouNeed()
var formServerUrl = 'https://server.example.com/_layouts/CustomPage.aspx'
this.href = formServerUrl
});
})
</script>
Have a look at the ServerFiles in the 12 Hive under 'Template\XML'. This has file extensions and a mapping to a redirect URL.
You can see there is a mapping for XSN and XML files in relation to InfoPath.
I haven't tried this and obviousily the normal caveats apply when altering files in the 12 Hive.

Resources