This blog post contains outdated information.
The cited code snippets may be workarounds, and be part of the official API in the meantime.
HTML5: Display and Handle FormCheckBox Fields
The Text Control Reporting engine MailMerge can populate fields automatically during the merge process. These fields can be also combined with MS Word compatible form fields such as checkboxes. This sample project shows how to display checkbox fields in the HTML5 based Web.TextControl and how to handle the Javascript event TextFieldClicked. The following method loads the document into a temporary ServerTextControl to loop through all ApplicationFields. When FormCheckBoxes are found, a…

The Text Control Reporting engine MailMerge can populate fields automatically during the merge process. These fields can be also combined with MS Word compatible form fields such as checkboxes.
This sample project shows how to display checkbox fields in the HTML5 based Web.TextControl and how to handle the Javascript event TextFieldClicked.

The following method loads the document into a temporary ServerTextControl to loop through all ApplicationFields. When FormCheckBoxes are found, a Checked or Unchecked Unicode character is set based on the checked status of the field.
/********************************************************
* ProcessCheckboxFields method
* desc: Sets the Unicode characters for all
* checkbox fields
* parameter: document - the document in the internal
* Text Control format
********************************************************/
private byte[] ProcessCheckboxFields(byte[] document)
{
// create a new temporary ServerTextControl
using (TXTextControl.ServerTextControl tx =
new TXTextControl.ServerTextControl())
{
// load the document
tx.Create();
tx.Load(document,
TXTextControl.BinaryStreamType.InternalUnicodeFormat);
// loop through all ApplicationFields
foreach (IFormattedText textPart in tx.TextParts)
{
foreach (ApplicationField field in textPart.ApplicationFields)
{
if ((field.TypeName != "FORMCHECKBOX"))
return null;
// create a new adapter field
FormCheckBox checkboxField = new FormCheckBox(field);
// select the field to change the font name
textPart.Selection.Start = checkboxField.Start - 1;
textPart.Selection.Length = checkboxField.Length;
textPart.Selection.FontName = "Arial Unicode MS";
// set the text (state)
checkboxField.Text =
checkboxField.Checked == true ? CHECKED : UNCHECKED;
}
}
tx.Save(out document, BinaryStreamType.InternalUnicodeFormat);
return document;
}
}
In the client-side Javascript, the TX Text Control event TextFieldClicked is used to update the AJAX UpdatePanel with the clicked field name as a parameter:
<script type="text/javascript">
// attach the 'textFieldClicked' event
TXTextControl.addEventListener("textFieldClicked", function (e) {
fieldClicked(e.fieldName, e.fieldType, e.typeName);
});
// do an AJAX postback on the UpdatePanel
function fieldClicked(fieldName, fieldType, typeName) {
__doPostBack('<%= UpdatePanel1.ClientID %>', fieldName);
}
</script>
In the code-behind, the AJAX call is processed and based on the argument, the clicked checkbox field is toggled.
protected void Page_Load(object sender, EventArgs e)
{
// handle the AJAX postback
string eventTarget =
Convert.ToString(Request.Params.Get("__EVENTTARGET"));
string eventArgument =
Convert.ToString(Request.Params.Get("__EVENTARGUMENT"));
// if the event argument is set, toggle the checkbox
if (eventArgument != null)
{
ToggleCheckBox(eventArgument);
}
}
Try the complete sample by cloning the repository from GitHub. Happy coding!
Download and Fork This Sample on GitHub
We proudly host our sample code on github.com/TextControl.
Please fork and contribute.
Requirements for this sample
- Visual Studio 2012 or better
- TX Text Control .NET Server (trial sufficient)
Related Posts
ASP.NET MVC: Implementing a Simplistic, Custom Button Bar
For some applications, the fully-featured ribbon bar might be too overloaded with features or the ribbon concept is not required in a project. Programmatically, all ribbon tabs, groups and buttons…
ASP.NET MVC: Adding Protected Sections to Documents
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…
ASP.NETReportingElectronic Signature
ASP.NET: Adding Electronic Signatures to Documents
An electronic signature is in many processes legally sufficient to prove an identity. According to the U.S. Federal ESIGN Act passed in 2000, an electronic signature is an: Electronic sound,…
Creating Your First ASP.NET Reporting Application
This tutorial shows how to use the MailMerge component in an ASP.NET Web application to merge a template with data to create an Adobe PDF document.
Automatically Reconnect to the Server and Recover the Document
We just published a sample project that shows how to reconnect to the server and how to recover the current document.