Products Technologies Demo Docs Blog Support Company

Using the MVC DocumentViewer in ASP.NET Web Forms

The ASP.NET MVC DocumentViewer for ASP.NET provides more features including document signing capabilities than the DocumentViewer for Web Forms. This article shows how to use the MVC DocumentViewer in an ASP.NET Web Forms project.

Using the MVC DocumentViewer in ASP.NET Web Forms

The ASP.NET MVC DocumentViewer for ASP.NET provides more features and functionality including document signing capabilities and annotations that are not supported by the Web Forms version of the DocumentViewer. This article shows how to use the MVC DocumentViewer in an ASP.NET Web Forms project.

Adding MVC Support

Adding MVC support to existing Web Forms projects can be easily done by adding the MVC NuGet package (https://www.nuget.org/packages/Microsoft.AspNet.Mvc/) to your project. As this is a requirement by the MVC DocumentViewer, all you need to do is to add the MVC DocumentViewer NuGet package to your Web Forms project.

  1. Click Manage NuGet Packages for Solution... from the Tools -> NuGet Package Manager main menu.

    NuGet Package

    Search for txtextcontrol.web.documentviewer and select the TXTextControl.Web.DocumentViewer package and click Install to add the package to your project.

  2. Click Add Reference... from theProject main menu. In the opened Reference Manager, click on Browse... and find the TX Text Control Assembly folder that is located in the installation directory of TX Text Control .NET Server:

    C:\Program Files\Text Control GmbH\TX Text Control 29.0.NET Server for ASP.NET\Assembly\

    Select the 3 files TXDocumentServer.dll, TXTextControl.dll and TXTextControl.Server.dll and confirm with Add.

  3. In the Solution Explorer, select the project and choose Add New Item... from the Project main menu. Select General -> Text File as the template, name it licenses.licx and confirm with Add.

    Paste the following string into the newly created file:

    TXTextControl.ServerTextControl, TXTextControl.Server, Culture=neutral, PublicKeyToken=6b83fe9a75cfb638

  4. The MVC routing must be added to the RouteConfig.cs file. In the Solution Explorer, open the RouteConfig.cs in the App_Start folder and add this route to the RegisterRoutes method:

    routes.MapRoute(
       name: "Default",
       url: "{controller}/{action}/{id}",
       defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
    );

    Your complete RouteConfig.cs should look similar to this:

    using System;
    using System.Collections.Generic;
    using System.Web;
    using System.Web.Mvc;
    using System.Web.Routing;
    using Microsoft.AspNet.FriendlyUrls;
    
    namespace webforms_js_viewer
    {
        public static class RouteConfig
        {
            public static void RegisterRoutes(RouteCollection routes)
            {
                var settings = new FriendlyUrlSettings();
                settings.AutoRedirectMode = RedirectMode.Permanent;
                routes.EnableFriendlyUrls(settings);
    
                routes.MapRoute(
                   name: "Default",
                   url: "{controller}/{action}/{id}",
                   defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
                );
          }
        }
    }
  5. In any Web Form (ASPX), add the following code to initialize the MVC DocumentViewer using JavaScript:

    <script src="https://localhost:44323/TextControl/GetResource?Resource=minimized.tx-viewer.min.js"></script>
    
    <style>
     #txViewerHost {
       width: 1000px;
       height: 800px;
     }
    </style>
    
    <div id="txViewerHost"></div>
    
    <script>
      // create a new DocumentViewer
      TXDocumentViewer.init( {
        containerID: 'txViewerHost',
        viewerSettings: {
          toolbarDocked: true,
          dock: "Fill",
          isSelectionActivated: true,
          showThumbnailPane: true,
              basePath: 'https://localhost:44323',
        }
      });
    </script>

    Make sure to replace https://localhost:44323 with your actual location and port number.

In a default Web Forms application, the results should look like in the screenshot below:

DocumentViewer

Stay in the loop!

Subscribe to the newsletter to receive the latest updates.

ASP.NET

Integrate document processing into your applications to create documents such as PDFs and MS Word documents, including client-side document editing, viewing, and electronic signatures.

ASP.NET Core
Angular
Blazor
JavaScript
React
  • Angular
  • Blazor
  • React
  • JavaScript
  • ASP.NET MVC, ASP.NET Core, and WebForms

Learn more Trial token Download trial

Related Posts

ASP.NETJavaScriptAnnotations

Deploying Documents with Annotations

The DocumentViewer allows to add and share annotations from different users to any type of document supported by TX Text Control including PDF, DOC, DOCX, RTF and the internal TX Text Control…


ASP.NETJavaScriptDocument Editor

Detect Toggle Button Changes Using a MutationObserver

This article shows how to detect changes of toggle buttons in the ribbon of the web editor using a MutationObserver. The state of a toggle button in the ribbon visualizes the state of a certain…


AngularASP.NETDocument Processing

Creation of Custom Electronic Signature Boxes

This article describes the customization of electronic signature boxes. It contains further explanations including the creation of templates and shows all code snippets required. The step-by-step…


ASP.NETDocumentViewerElectronic Signature

DocumentViewer Preview: Completing Form Fields

We just published a pre-release version of the DocumentViewer for ASP.NET (Core) that supports the completion of form fields within a document signing process.


ASP.NETDocumentViewerMVC

DocumentViewer for .NET Core 3.1 Released

We just published a multi-platform NuGet package including a .NET Core version of the TX Text Control DocumentViewer.