Prasad Bolla's SharePoint Blog

Click Here to go through the Interesting posts within my Blog.

Click Here to go through the new posts in my blog.

Wednesday, February 27, 2013

How to use SharePoint RichTextBox within a Visual webPart




Ascx
<%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
<%@ Assembly Name="Microsoft.Web.CommandUI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
<%@ Import Namespace="Microsoft.SharePoint" %>
<%@ Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="SPRTBoxUserControl.ascx.cs" Inherits="SPRTBox.SPRTBox.SPRTBoxUserControl" %>
<table>
<tr>
<td>
<SharePoint:InputFormTextBox  runat="server" ID="rtTest" ValidationGroup="CreateCase" Rows="8" Columns="40" RichText="true" RichTextMode="Compatible" AllowHyperlink="true" TextMode="MultiLine" />
</td>
</tr>
<tr><td><asp:Button ID="btnSave" runat="server" Text="Save"
        onclick="btnSave_Click" /></td></tr>
</table>
Ascx.Cs
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using System.Security;

namespace SPRTBox.SPRTBox
{
    public partial class SPRTBoxUserControl : UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    SPListItemCollection myColl = SPContext.Current.Web.Lists["RT Test"].Items;
                    SPListItem item = myColl.Add();
                    item["Title"] = "New Record";
                    item["Test"] = rtTest.Text;
                    item.Update();
                });
            }
            catch (Exception Ex)
            {
                Response.Write(Ex.ToString());
            }
        }
    }
}

1 comment: