# Web Forms Document Viewer (Legacy)

> The legacy Web Forms DocumentViewer control with DocumentController: register it on a page, load documents, fill in form fields, SaveDocument and SaveFormData.

- **Product:** TX Text Control .NET Server
- **Section:** Documentation
- **Kind:** Topic
- **Path:** TX Text Control .NET Server > Integration Guide > ASP.NET on .NET Framework > Web Forms Document Viewer (Legacy)
- **4205 words**
- **Web URL:** https://docs.textcontrol.com/tx-text-control-dotnet-server/integration/dotnet-framework/web-forms-viewer/
- **LLMs URL:** https://docs.textcontrol.com/tx-text-control-dotnet-server/integration/dotnet-framework/web-forms-viewer/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/tx-text-control-dotnet-server/integration/dotnet-framework/web-forms-viewer/llms-full.txt

---

Before the HTML5 Document Viewer, ASP.NET Web Forms applications displayed documents with a server control of its own: [DocumentServer.Web.DocumentViewer](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/txtextcontrol-documentserver-web/documentviewer/llms-full.txt), introduced in version 15.0, together with the [DocumentServer.DocumentController](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/txtextcontrol-documentserver/documentcontroller/llms-full.txt) that loads and prepares the documents on the server. The reference of version 34.0 still documents both classes. What follows is for maintaining Web Forms applications that use them.

**Legacy control.** Text Control's current guides don't cover this control, and it lacks features of the HTML5 Document Viewer, such as annotations and document signing. For new pages, use the [ASP.NET MVC Document Viewer](https://docs.textcontrol.com/tx-text-control-dotnet-server/integration/dotnet-framework/mvc-viewer/llms-full.txt) on the .NET Framework, which the blog article [Using the MVC DocumentViewer in ASP.NET Web Forms](https://www.textcontrol.com/blog/2021/08/12/using-the-mvc-documentviewer-in-aspnet-web-forms/) also adds to Web Forms projects, or the viewer in [ASP.NET Core](https://docs.textcontrol.com/tx-text-control-dotnet-server/getting-started/document-viewer/aspnet-core/llms-full.txt).

### How the Viewer Works

- **`DocumentViewer`** is an ASP.NET server control in the namespace `TXTextControl.DocumentServer.Web`, derived from `System.Web.UI.WebControls.CompositeControl`. It shows the pages of a document in the browser, with a toolbar for navigating and zooming. It can't edit the text of a document, but in edit mode it shows input fields for the form fields of a document.
- **`DocumentController`** in the namespace `TXTextControl.DocumentServer` does the document handling on the server. It is a component derived from `System.ComponentModel.Component` and works with a `ServerTextControl`, which you assign to its [TextComponent](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/txtextcontrol-documentserver/documentcontroller/textcomponent-property/llms-full.txt) property. Its methods throw an exception when `TextComponent` is not set.
- **The viewer uses the controller** that you assign to its [DocumentController](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/txtextcontrol-documentserver-web/documentviewer/documentcontroller-property/llms-full.txt) property.

### Set Up the Page

The setup below follows Text Control's GitHub sample [TextControl.DocumentViewer.Styles](https://github.com/TextControl/TextControl.DocumentViewer.Styles), a Web Forms project last updated for version 32.0. It references these assemblies from the *Assembly* folder of the installation: *TXDocumentServer.dll*, *TXDocumentServer.Web.DocumentViewer.dll*, *TXDrawing.dll*, *TXDrawing.Windows.Forms.dll*, *TXTextControl.dll* and *TXTextControl.Server.dll*. Check that the folder of your installation contains *TXDocumentServer.Web.DocumentViewer.dll* before you start.

Because the controller uses `ServerTextControl`, the project needs a *licenses.licx* file with this line for version 34.0:

```text
TXTextControl.ServerTextControl, TXTextControl.Server, Version=34.0.1900.500, Culture=neutral, PublicKeyToken=6b83fe9a75cfb638
```

The page registers the control under a tag prefix and places it in an `UpdatePanel`, which needs a `ScriptManager` on the page:

```html
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="index.aspx.cs" Inherits="ViewerApp.index" %>

<%@ Register Assembly="TXDocumentServer.Web.DocumentViewer" Namespace="TXTextControl.DocumentServer.Web" TagPrefix="cc1" %>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>DocumentViewer</title>
</head>
<body>
    <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>

        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
                <cc1:DocumentViewer ID="DocumentViewer1" runat="server" Height="400px" Width="795px" />
            </ContentTemplate>
        </asp:UpdatePanel>
    </form>
</body>
</html>
```

The code-behind creates the controller, connects it to a `ServerTextControl` and to the viewer and loads a document:

```csharp
using System;
using System.Web.UI;

namespace ViewerApp
{
    public partial class index : Page
    {
        private TXTextControl.DocumentServer.DocumentController documentController1;
        private TXTextControl.ServerTextControl serverTextControl1;

        protected void Page_Load(object sender, EventArgs e)
        {
            // The controller does its work with a ServerTextControl
            documentController1 = new TXTextControl.DocumentServer.DocumentController();
            serverTextControl1 = new TXTextControl.ServerTextControl();
            documentController1.TextComponent = serverTextControl1;

            DocumentViewer1.DocumentController = documentController1;
            DocumentViewer1.LoadDocument(
                Server.MapPath("documents/Demo.rtf"),
                TXTextControl.DocumentServer.FileFormat.RichTextFormat);
        }
    }
}
```

- [LoadDocument](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/txtextcontrol-documentserver-web/documentviewer/loaddocument-method/llms-full.txt) loads a file from a path on the server. With the path alone, the file type is taken from the extension; the second parameter sets it explicitly as a [FileFormat](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/txtextcontrol-documentserver/fileformat/enumeration/llms-full.txt) value: `MSWord`, `RichTextFormat`, `WordprocessingML` or `InternalUnicodeFormat`.
- [LoadDocumentFromMemory](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/txtextcontrol-documentserver-web/documentviewer/loaddocumentfrommemory-method/llms-full.txt) loads a document from a variable, for example a document that `MailMerge` has just created.
- [DocumentPath](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/txtextcontrol-documentserver-web/documentviewer/documentpath-property/llms-full.txt) is the alternative to a method call: the viewer loads the file the next time it is initialized. The extension of the file must match its type, because the viewer passes the type it derives from the extension to the controller.

### Navigate and Zoom

| Property | Purpose |
|---|---|
| [PageNumber](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/txtextcontrol-documentserver-web/documentviewer/pagenumber-property/llms-full.txt) | The page the viewer shows, from 1 to the number of pages. 0 when no document is loaded. |
| [TotalPages](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/txtextcontrol-documentserver-web/documentviewer/totalpages-property/llms-full.txt) | The number of pages of the loaded document. Read only. |
| [ZoomTo](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/txtextcontrol-documentserver-web/documentviewer/zoomto-property/llms-full.txt) | `ControlWidth` (the default), `WholePage` or `FixedSize`. |
| [ZoomFactor](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/txtextcontrol-documentserver-web/documentviewer/zoomfactor-property/llms-full.txt) | The zoom in percent, 10 to 400. Used only when `ZoomTo` is `FixedSize`. |
| [ToolBar](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/txtextcontrol-documentserver-web/documentviewer/toolbar-property/llms-full.txt) | Shows or hides the toolbar. |
| [ShowEditButton](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/txtextcontrol-documentserver-web/documentviewer/showeditbutton-property/llms-full.txt) | Shows or hides the edit button. Since version 23.0. |
| [PageAnimations](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/txtextcontrol-documentserver-web/documentviewer/pageanimations-property/llms-full.txt), [PageAnimationDuration](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/txtextcontrol-documentserver-web/documentviewer/pageanimationduration-property/llms-full.txt) | CSS transitions when the user turns pages, and their duration in seconds. Since version 23.0. |
| [RoundedPageCorners](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/txtextcontrol-documentserver-web/documentviewer/roundedpagecorners-property/llms-full.txt) | Draws the pages with rounded corners. Since version 23.0. |
| [Interpolation](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/txtextcontrol-documentserver-web/documentviewer/interpolation-property/llms-full.txt), [InterpolationMode](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/txtextcontrol-documentserver-web/documentviewer/interpolationmode-property/llms-full.txt) | The quality of the rendered pages: `None` (the default) up to `Interpolation4x`, and a `System.Drawing.Drawing2D.InterpolationMode`. Higher quality renders more slowly. |

The look of the toolbar and the pages is set with CSS; the GitHub sample above replaces the button images and the background with a style sheet.

### Fill In Form Fields

With [EditMode](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/txtextcontrol-documentserver-web/documentviewer/editmode-property/llms-full.txt) set to `Edit`, the viewer shows an input field at the position of every form field of the document; the default, `ReadOnly`, shows the document only. [FieldBorderStyle](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/txtextcontrol-documentserver-web/documentviewer/fieldborderstyle-property/llms-full.txt) (`None`, `Dashed`, `Dotted` or `Solid`, the default) and [FieldBorderColor](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/txtextcontrol-documentserver-web/documentviewer/fieldbordercolor-property/llms-full.txt) set the borders of the fields in edit mode.

To get what the user entered, call [SaveUserInput](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/txtextcontrol-documentserver-web/documentviewer/saveuserinput-method/llms-full.txt), for example in the click handler of a button. The method raises the [SaveFormData](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/txtextcontrol-documentserver-web/documentviewer/saveformdata-event/llms-full.txt) event, whose [FormData](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/txtextcontrol-documentserver-web/documentviewer-saveformdataeventargs/formdata-property/llms-full.txt) property holds the input as a `System.Data.DataTable`:

```csharp
// Attach the handler in Page_Load:
// DocumentViewer1.SaveFormData += DocumentViewer1_SaveFormData;

private void DocumentViewer1_SaveFormData(object sender,
    TXTextControl.DocumentServer.Web.DocumentViewer.SaveFormDataEventArgs e)
{
    // Store the form input as XML
    e.FormData.WriteXml(Server.MapPath("~/App_Data/formdata.xml"));
}
```

On the server, the controller sets the value of a form field with [MergeField](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/txtextcontrol-documentserver/documentcontroller/mergefield-method/llms-full.txt), which takes the field's `FormFieldAdapter` and the new value. [GetFieldAdapters](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/txtextcontrol-documentserver/documentcontroller/getfieldadapters-method/llms-full.txt) returns the adapters of all fields, or of the fields of one page, as a [FieldAdapterCollection](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/txtextcontrol-documentserver/documentcontroller-fieldadaptercollection/llms-full.txt). Check boxes are drawn with the character codes [CharCodeChecked](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/txtextcontrol-documentserver/documentcontroller/charcodechecked-property/llms-full.txt) (254) and [CharCodeUnchecked](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/txtextcontrol-documentserver/documentcontroller/charcodeunchecked-property/llms-full.txt) (168) of the [CheckBoxFont](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/txtextcontrol-documentserver/documentcontroller/checkboxfont-property/llms-full.txt), Wingdings by default.

### Save the Document

[Save](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/txtextcontrol-documentserver-web/documentviewer/save-method/llms-full.txt) has three overloads:

- `Save(string path)` and `Save(string path, FileFormat format)` save the document to a path on the server. Build the path with `Server.MapPath`.
- `Save(FileFormat format)` raises the [SaveDocument](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/txtextcontrol-documentserver-web/documentviewer/savedocument-event/llms-full.txt) event instead, and your handler decides what happens to the document. [Document](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/txtextcontrol-documentserver-web/documentviewer-savedocumenteventargs/document-property/llms-full.txt) holds it as a byte array, and [FileFormat](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/txtextcontrol-documentserver-web/documentviewer-savedocumenteventargs/fileformat-property/llms-full.txt) its format.

```csharp
// Attach the handler in Page_Load:
// DocumentViewer1.SaveDocument += DocumentViewer1_SaveDocument;

private void DocumentViewer1_SaveDocument(object sender,
    TXTextControl.DocumentServer.Web.DocumentViewer.SaveDocumentEventArgs e)
{
    // Write the snapshot of the document to a file
    System.IO.File.WriteAllBytes(Server.MapPath("~/App_Data/result.docx"), e.Document);
}
```

For `RichTextFormat`, the reference writes the bytes as ASCII text with `System.IO.File.WriteAllText` instead.

### DocumentController Members

The controller also works without the viewer, as a helper for templates:

| Member | Purpose |
|---|---|
| [Load](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/txtextcontrol-documentserver/documentcontroller/load-method/llms-full.txt), [LoadFromMemory](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/txtextcontrol-documentserver/documentcontroller/loadfrommemory-method/llms-full.txt) | Load a document from a file or from memory in a `FileFormat`. Return `false` when the document can't be loaded. |
| [Save](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/txtextcontrol-documentserver/documentcontroller/save-method/llms-full.txt), [SaveToMemory](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/txtextcontrol-documentserver/documentcontroller/savetomemory-method/llms-full.txt) | Save the loaded document to a file with a `StreamType`, or to a byte array or string, with `SaveSettings`. |
| [GetFieldNames](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/txtextcontrol-documentserver/documentcontroller/getfieldnames-method/llms-full.txt) | The names of the application fields of the document. |
| [GetBlockNames](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/txtextcontrol-documentserver/documentcontroller/getblocknames-method/llms-full.txt), [GetBlockFieldNames](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/txtextcontrol-documentserver/documentcontroller/getblockfieldnames-method/llms-full.txt) | The names of the merge blocks, and of the fields in one block. |
| [Pages](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/txtextcontrol-documentserver/documentcontroller/pages-property/llms-full.txt) | The pages of the loaded document. |
| [DpiX](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/txtextcontrol-documentserver/documentcontroller/dpix-property/llms-full.txt), [DpiY](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/txtextcontrol-documentserver/documentcontroller/dpiy-property/llms-full.txt), [Twips2Pixels](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/txtextcontrol-documentserver/documentcontroller/twips2pixels-method/llms-full.txt) | The resolution for display calculations, 96 by default, and a conversion from twips to pixels for pixel-based viewers. |

### Next Steps

- [ASP.NET MVC Document Viewer](https://docs.textcontrol.com/tx-text-control-dotnet-server/integration/dotnet-framework/mvc-viewer/llms-full.txt): the current viewer on the .NET Framework.
- [ASP.NET Web Forms Document Editor](https://docs.textcontrol.com/tx-text-control-dotnet-server/integration/dotnet-framework/web-forms-editor/llms-full.txt): the editor control of Web Forms.
- [.NET Framework Applications](https://docs.textcontrol.com/tx-text-control-dotnet-server/deployment/windows/dotnet-framework/llms-full.txt): the files to deploy.

---

## Nearby

- **Previous:** [ASP.NET Web Forms Document Editor](https://docs.textcontrol.com/tx-text-control-dotnet-server/integration/dotnet-framework/web-forms-editor/llms-full.txt)
- **Next:** [Deployment Guide](https://docs.textcontrol.com/tx-text-control-dotnet-server/deployment/llms-full.txt)
