Sharepoint adding customcontrol to web-part error - sharepoint

I am new in Sharepoint. I have created customcontrol and added it to web-part. I have registered control:
<%# Register TagPrefix="UserControls" TagName="FormContactUs"
Src="~/_CONTROLTEMPLATES/FormContactUs.ascx" %>
<%# Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages"
Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<UserControls:FormContactUs runat="server" id="formContactUs" Mode="Colleague" />
But it returns error : "element 'FormContactUs' is unknown element. This can occur if there is a compilation error or the web.config file is missing "
Please any ideas where the issue can be.. Thanks!

You need to reference the usercontrol like this:
<UserControls:FormContactUs runat="server" ID="formContactUs" Mode="Colleague" />
Happy coding!

Related

Kentico event calendar widget source code

I can't find the source code for the html used for the calendar table. I have the webpart, but not the html for the table. I need to strip the inline CSS and attributes.
Following is the markup for the event calendar (obviously this is what you see):
<%# Control Language="C#" AutoEventWireup="true"
Inherits="CMSWebParts_EventManager_EventCalendar" CodeFile="~/CMSWebParts/EventManager/EventCalendar.ascx.cs" %>
<div class="Calendar">
<cms:CMSCalendar ID="calItems" runat="server" EnableViewState="false" />
</div>
<div class="EventDetail">
<cms:CMSRepeater ID="repEvent" runat="server" Visible="false" StopProcessing="true" EnableViewState="false" />
</div>
So what you see on the live page is created by CMSCalendar control, which leaves in CMS.Controls library, which means you can't modify it unless you have full source code of Kentico.
I'd try to change the appearance of this control with CSS, if CSS doesn't work there is javascript/jQuery.
Have you looked into creating a skin? You can change the css classes used if needed.
Might help some

using rich textbox in Sharepoint 2013

I want to use a rich textbox in Sharepoint 2013 as seen in the figure below. How can I do that?
I have already used the code below.
<%# Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<SharePoint:InputFormTextBox ID="RichTextField1" runat="server" TextMode="MultiLine" RichTextMode="FullHtml" Columns="20" Rows="10"/>
but I could not get what I need. I got a simple multiline textbox with scroll.
Thank you for the answers.
try adding this in
RichText="true"
more or less it would be like this as a sample:
<SharePoint:InputFormTextBox ID="rftDefaultValue"
RichText="true"
RichTextMode="FullHtml" runat="server"
TextMode="MultiLine" Rows="5">
</SharePoint:InputFormTextBox>
also, if you're viewing this using chrome, it would only show as a plain text box, try viewing this using IE :)
Rich Text boxes are an old issue on non IE browsers, if you want to use the abilities of the rich text you will have to use IE.
You can implement other rich text editors on your sharepoint site like tinymce http://joshmccarty.com/2011/06/use-tinymce-as-the-rich-text-editor-in-sharepoint-forms/
I have used this external (cross platform) content editor: http://nicedit.com/index.php and it worked perfectly for me.
And it looks like this:

Converting MVC application to Orchard CMS

I'm an Orchard newbie, and I have a newbie question.
I am converting an existing mvc application to Orchard, and in order to practice for the real thing, I am trying to convert the contoso university sample MVC app to Orchard to learn the basics.
I have been through creating a module for it, adding menu elements to access the app, and I have also been able to display the output from the Home\Index action, so that I know that the module is set up correctly.
Now I am trying to add the Home\About action, which will display a table that is produced from a database query.
This gives me the following error:
MSDTC on server 'DEV\SQLEXPRESS' is unavailable. Description: An
unhandled exception occurred during the execution of the current web
request. Please review the stack trace for more information about the
error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: MSDTC on server
'DEV\SQLEXPRESS' is unavailable.
Source Error:
Line 17: Line 18: Line 19: #foreach (var item in Model) {
Line 20: Line 21:
Source File: c:\Users\dev1\Documents\My Web Sites\Orchard
CMS\Modules\ContosoUniversity\Views\Home\About.cshtml Line: 19
Source File: c:\Users\dev1\Documents\My Web Sites\Orchard
CMS\Modules\ContosoUniversity\Views\Home\About.cshtml Line: 19
Now, after some googling, I understand that this has something to do with the need for suppressing ambient transactions. So I add a using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Suppress)) to my home controller:
public class HomeController : Controller
{
private SchoolContext db = new SchoolContext();
[Themed]
public ActionResult Index()
{
ViewBag.Message = "Welcome to Contoso University!";
return View();
}
[Themed]
public ActionResult About()
{
using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Suppress))
{
var query = "SELECT EnrollmentDate, COUNT(*) AS StudentCount "
+ "FROM Person "
+ "WHERE EnrollmentDate IS NOT NULL "
+ "GROUP BY EnrollmentDate";
var data = db.Database.SqlQuery(query);
return View(data);
}
}
However, it does not help. I have read other places to Surround your data access code with this, but as I am using entity framework, I am not explicitly opening any data connections, and hence I am not sure where to put the using statement.
I think the problem here is that the actual execution of the query is delayed and actually does not happen within the transaction scope block. If you would just call ToList() on your SQL query, that would probably fix it. It's also good practice because you don't want the actual querying to happen in the view. What you are currently sending to the view is not data, it's a query.
What type is db.Database.SqlQuery() returning? Can you include the code for your view and for the model that view is using?
From this error message it looks like data access is happening from the razor view. If this is the case, you can fix it by wrapping your foreach (var item in Model) { ...} with a using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Suppress)) {...} block.
You might need to import the proper namespaces into the razor view in order for the TransactionScope stuff to work from there. If I remember correctly, I had to add <add assembly="System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /> inside the <system.web> <compilation> <assemblies> block in the Orchard.Web\web.config.
Thanks to Bertrand Le Roy and Giscard Biamby for pushing me in the right direction.
I agree with Bertrand that it would make sense to add a ToList in the controller to force execution of the query, but that did not help. What I had to do was to add a suppress clause in the view like this:
<table>
<tr>
<th>
Enrollment Date
</th>
<th>
Students
</th>
</tr>
#using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Suppress))
{
foreach (var item in Model)
{
<tr>
<td>
#String.Format("{0:d}", item.EnrollmentDate)
</td>
<td>
#item.StudentCount
</td>
</tr>
}
}
</table>
I also had to add a using statement in the top part of the view:
#model IEnumerable<ContosoUniversity.ViewModels.EnrollmentDateGroup>
#using System.Transactions
And finally, in order to be allowed to use the reference, I had to add the System.Transactions assembly in web.config:
<system.web>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly ="System.Transactions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
</assemblies>
</compilation>
Now I don't get any errors, but I don't get any data either, but that's another issue. I am sure this is a step in the right direction.
I would wish there would be a way to do this at a higher level to avoid having to change all my views, but at least I will be able to make it work.

Sharepoint DataFormWebPart

Within my DataFormWebPart I have a 'DataSourcesString' property which references and queries a list.
Depending on what page the DataFormWebPart is displayed on I need to be able to configure the query (parameterise the string 'Dispute Resolution' in the code below) within the 'DataSourcesString'.
Does anyone know if there a way to paramterise this by modifying the web part through either the XSL Editor or Paramter Editor?
The web part code snippet relating to the 'DataSourcesString' is below
<property name="DataSourcesString" type="string"><%# Register TagPrefix="sharepoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %><sharepoint:SPDataSource runat="server" DataSourceMode="List" SelectCommand="&lt;View&gt;&lt;Query&gt;&lt;OrderBy&gt;&lt;FieldRef Name=&quot;ID&quot;/&gt;&lt;/OrderBy&gt;&lt;Where&gt;&lt;Eq&gt;&lt;FieldRef Name=&quot;Primary&quot;/&gt;&lt;Value Type=&quot;Text&quot;&gt;Dispute Resolution&lt;/Value&gt;&lt;/Eq&gt;&lt;/Where&gt;&lt;/Query&gt;&lt;/View&gt;" UseInternalName="True" IncludeHidden="True" ID="datasource1">
Thanks! I appreciate this may not be so clear without screenshots..
You can do this using a QueryString parameter on the DataForm. I'm assuming you're only able to export the webpart. So, export the webpart and save the .webpart to your desktop. Open it and modify it like so:
In your DataSourcesString remove the where clause entirely:
<property name="DataSourcesString" type="string"><%# Register TagPrefix="sharepoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %><sharepoint:SPDataSource runat="server" DataSourceMode="List" SelectCommand="&lt;View&gt;&lt;Query&gt;&lt;OrderBy&gt;&lt;FieldRef Name=&quot;ID&quot;/&gt;&lt;/OrderBy&gt;&lt;/Query&gt;&lt;/View&gt;" UseInternalName="True" IncludeHidden="True" ID="datasource1">
In the <property name="ParameterBindings" type="string"> node, add:
<ParameterBinding Name="MyVariable" Location="QueryString(MyVar)"/>
In the XSL for the webpart itself, find <xsl:param name="dvt_partguid" /> and just below it add:
<xsl:param name="MyVar" />
Finally, find select="/dsQueryResponse/Rows/Row and modify it to be:
select="/dsQueryResponse/Rows/Row[#Primary='$MyVar']
Save the webpart, upload it back, and you should now be able to filter it by adding MyVar=Whatever to your querystring
The only way I found of manipulating parameters at run time was from C# code behind.
Here are the steps required:
Dump your DataFormWebPart code into an ascx control. (or a custom webpart if you wish).
In the code behind of the control, reference your DataFormWebPart via it's ID just like you would to any other user control such as a text box.
Use the DataFormWebPart object to fiddle with its Data Source (if required) and its queries. You can get a handle on all of its parameters.

How to output Site title on a sharepoint masterpage

I have a custom masterpage in sharepoint and want to output the site title in a different part of the page. Currently I can see the site title which is outputted using the following code:
<asp:ContentPlaceHolder id="PlaceHolderMain" runat="server" Visible="true" />
Apparently using
<asp:ContentPlaceHolder id="PlaceHolderPageTitleInTitleArea" runat="server" Visible="true" />
Should also output the title but is returning nothing. Any ideas what is going wrong?
The Code you have mentioned are the Content Place Holders where you can replace the Content, You can place the register the below tag in the top the page and
<%# Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
And place the below code to get the Title of the Page
<SharePoint:ProjectProperty Property="Title" runat="server" />
If you want to do that in the master page level you can do with the below code
<asp:ContentPlaceHolder id="PlaceHolderPageTitleInTitleArea" runat="server" Visible="true">
<SharePoint:ProjectProperty Property="Title" runat="server" />
</asp:ContentPlaceHolder>
Unless you override the above content place holder you will get the Title of the Web Automatically
This can be done by using the ProjectProperty control (see http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.webcontrols.projectproperty.aspx)
<asp:ContentPlaceHolder id="PlaceHolderPageTitleInTitleArea" runat="server">
<SharePoint:ProjectProperty property="Title" runat="server" />
</asp:ContentPlaceHolder>

Resources