This documentation is archived and is not being maintained.

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

public class TextView : PagedControl
public class TextView extends PagedControl
public class TextView extends PagedControl
Not applicable.

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 Introduction to 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="" >
    <mobile:form id="form1" runat="server" paginate="true">
        <mobile:TextView id="Primes" runat="server" 
            OnLoadItems="Primes_OnLoadItems" />

  • AspNetHostingPermission  for operating in a hosted environment. Demand value: LinkDemand; Permission value: Minimal.
  • AspNetHostingPermission  for operating in a hosted environment. Demand value: InheritanceDemand; Permission value: Minimal.

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 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1