TX Text Control Blog

ASP.NET MVC: Adding protected sections to documents

Björn Meyer

Blogged by Björn Meyer on March 1, 2017 and tagged with html5, reporting, github, asp.net.

A SubTextPart object represents a user-defined range of text in a TX Text Control document. A SubTextPart is basically a range of text with a Name and an ID property to store additional information.

In the implementation of the MailMerge class, a SubTextPart is used for repeating blocks in a reporting template. But the SubTextParts can be used for many different applications such as adding comments or to store additional hidden information to text ranges.

This sample shows how to insert a SubTextPart to protect a section from being edited by the user. The ID property is used to mark the SubTextPart as editable (0) or non-editable (1). In order to insert this special SubTextPart, an HTTP Post method is implemented in the MVC controller:

This method creates a ServerTextControl that is used to load the selected text of the Web.TextControl. This text is converted into a SubTextPart and saved in the internal Unicode format to be returned to the client.

On client side, using JavaScript, the above HTTP Post method InsertSubTextPart is called using a jQuery AJAX call. If the selection length is larger than 0, the selection is being saved and sent to the controller method. The returned Base64 encoded binary internal Unicode format is loaded back into the selection:

If the caret is entering and leaving these SubTextParts, events are triggered that are used to set the editMode property of Web.TextControl either to ReadAndSelect or Edit mode.

In the following screenshot, you can see an activated SubTextPart which is protected. The ribbon bar is disabled as the content is not editable inside this protected section.

ASP.NET MVC: Adding protected sections to documents

Download the sample from GitHub and test it on your own.

Download and fork this sample on GitHub

We proudly host our sample code on github.com/textcontrol. Feel free to fork and contribute!

Download ZIP

Open repository on GitHub

Open in Visual Studio

Requirements for this sample

  • at least Visual Studio 2015
  • At least a trial version of TX Text Control .NET Server for ASP.NET
Call us: +1 704-544-7445 (United States)





Buy Now

About Text Control

Founded in 1991, Text Control is an award-winning Visual Studio Industry Partner and leading vendor of word processing and reporting components for Microsoft development technologies. The products help thousands of developers add comprehensive word processing functionality to their applications. Text Control is 100% self-owned and independent of all investor decisions. Customers benefit from these years of experience, large user-base, and at the same time, appreciate developing with a mature, reliable product.

SD Times 100SD Times 100SD Times 100SD Times 100SD Times 100SD Times 100Visual Studio 2015 Launch PartnerVisual Studio 2013 Launch PartnerVisual Studio 2012 Launch PartnerVisual Studio Partner