TextView Class
Collapse the table of content
Expand the table of content

TextView Class

Provides a programmable control for displaying larger amounts of text, with optional markup tags on a mobile page.

Namespace:  System.Web.UI.MobileControls
Assembly:  System.Web.Mobile (in System.Web.Mobile.dll)

[AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public class TextView : PagedControl
<mobile:TextView />

Unlike literal text in a mobile form, you can set content of a TextView from code. Unlike a mobile Label control, you can include markup within the value of the Text property. Also, the TextView control is careful not to break up inserted elements such as links during pagination. For more information, see Literal Text Inside Form Markup.

If the TextView control is within a Panel, set the Panel.Paginate property to true to allow text to flow across multiple pages on mobile devices. If the TextView control is not in a Panel, put the name of the TextView control into the Form.ControlToPaginate property.

Most other properties and methods of the mobile TextView control are of more use to developers of new device adapters for rendering the contents on specific devices.

Caution noteCaution:

This control can be used to display user input, which might include malicious client script. Check any information that is sent from a client for executable script, SQL statements, or other code before displaying it in your application. You can use validation controls to verify user input before displaying the input text in a control. ASP.NET provides an input request validation feature to block script and HTML in user input. For more information, see Securing Standard Controls, How to: Protect Against Script Exploits in a Web Application by Applying HTML Encoding to Strings, and Validating User Input in ASP.NET Web Pages.

The following code example creates numbers and identifies each prime number in a sentence, and adds those sentences to the TextView control. The example also uses custom pagination to provide only a page full of text at a time.


The following code sample uses the single-file code model and may not work correctly if copied directly into a code-behind file. This code sample must be copied into an empty text file that has an .aspx extension. For more information, see ASP.NET Web Page Code Model.

<%@ Page Language="C#" 
    Inherits="System.Web.UI.MobileControls.MobilePage" %>
<%@ Register TagPrefix="mobile" 
    Assembly="System.Web.Mobile" %>

<script runat="server">
    // Returns an array of Boolean values 
    private bool[] TestPrimes(int from, int howMany)
        // Test a range of numbers to determine which are prime. 
        bool[] isPrime = new bool[howMany];

        int endAt = from + howMany - 1;
        for (int i = from; i < endAt; i++)
        {   // Set a default value of true
            isPrime[i - from] = true;

            int sqrt = (int)Math.Sqrt(i);
            for (int factor = 2; factor <= sqrt; factor++)
                if ((i % factor) == 0)
                {   // Set value as false
                    isPrime[i - from] = false;
        return isPrime;

    protected void Page_Load(object sender, EventArgs args)
        if (!IsPostBack)
            Primes.ItemCount = 2000;
            Primes.ItemsPerPage = 20;
            form1.ControlToPaginate = Primes;

    protected void Primes_OnLoadItems(object sender, LoadItemsEventArgs args)
        StringBuilder StrBldr = new StringBuilder();
        Primes.Text = "";

        // Start the list at 2. 
        int startNumber = args.ItemIndex + 2;
        bool[] isPrime;
        isPrime = TestPrimes(startNumber, args.ItemCount);

        for (int i = 0; i < args.ItemCount; i++)
            string message;
            if (isPrime[i])
                message = String.Format("<b>{0} is prime</b>", 
                    i + startNumber);
                message = String.Format("<b>{0}</b> is not prime", 
                    i + startNumber);

            StrBldr.Append("<br />");
        Primes.Text = StrBldr.ToString();

<html xmlns="http://www.w3.org/1999/xhtml" >
    <mobile:form id="form1" runat="server" paginate="true">
        <mobile:TextView id="Primes" runat="server" 
            OnLoadItems="Primes_OnLoadItems" />

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1

Community Additions

© 2015 Microsoft