Form.ControlToPaginate Свойство

Определение

Возвращает или задает элемент управления на форме, которая может быть разбита на страницы. По умолчанию равно null (Nothing в Visual Basic). Этот API устарел. Сведения о разработке ASP.NET мобильных приложений см. в статье Мобильные приложения & сайты с ASP.NET.

public:
 property System::Web::UI::Control ^ ControlToPaginate { System::Web::UI::Control ^ get(); void set(System::Web::UI::Control ^ value); };
[System.ComponentModel.Bindable(false)]
[System.ComponentModel.Browsable(false)]
public System.Web.UI.Control ControlToPaginate { get; set; }
[<System.ComponentModel.Bindable(false)>]
[<System.ComponentModel.Browsable(false)>]
member this.ControlToPaginate : System.Web.UI.Control with get, set
Public Property ControlToPaginate As Control

Значение свойства

Элемент управления на форме, которая может быть разбита на страницы.

Атрибуты

Примеры

В следующем примере кода показано, как использовать ControlToPaginate свойство класса , Form чтобы указать, какой элемент управления следует разбить на страницы.

В примере создается страница с двумя формами. Одна форма имеет очень длинную строку, которая на некоторых устройствах должна быть разбиения на страницы, чтобы предоставить пользователю доступ ко всему тексту. Чтобы увидеть разбиение на страницы в действии, необходимо просмотреть пример на устройстве, которое обрабатывает разбиение на страницы. В Visual Studio 2005 можно использовать один из эмуляторов устройств, доступных в диспетчере эмуляторов устройств в меню Сервис .

Примечание

В следующем примере кода используется однофайловая модель кода, и при копировании непосредственно в файл кода программной части может работать неправильно. Этот пример кода необходимо скопировать в пустой текстовый файл с расширением ASPX. Дополнительные сведения см. в разделе Общие сведения о синтаксисе страницы ASP.NET Web Forms.

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

<script Runat="server">
    //<Snippet7>
    void Form_Activate(object sender, EventArgs e)
    {
        Form1.Wrapping = Wrapping.NoWrap;
        string a = "This is a very long string <br />";
        string b = "START ";
        
        // Create a long string to force pagination
        for (int i = 0; i < 100; i++)
            b += a;
        
        txtView.Text = b + " END";
        Form1.ControlToPaginate = txtView;
    }
    //</Snippet7>

    //<Snippet5>
    void Form_Paginated(object sender, EventArgs e)
    {
        // Set the background color based on 
        // the number of pages
        if (ActiveForm.PageCount > 1)
            ActiveForm.BackColor = Color.LightBlue;
        else
            ActiveForm.BackColor = Color.LightGray;

        // Check to see if the Footer template has been chosen
        if (DevSpec.HasTemplates)
        {   
            System.Web.UI.MobileControls.Label lbl = null;
            
            // Get the Footer panel
            System.Web.UI.MobileControls.Panel pan = Form1.Footer;

            // Get the Label from the panel
            lbl = (System.Web.UI.MobileControls.Label)pan.FindControl("lblCount");
            // Set the text in the Label
            lbl.Text = "Page #" + Form1.CurrentPage.ToString();
        }
    }
    //</Snippet5>

    //<Snippet6>
    void Page_Load(object sender, EventArgs e)
    {
        // Set the pager text properties
        if (!IsPostBack)
            Form1.PagerStyle.NextPageText = "Go Next >";
        else
        {
            // For postback, set different text
            Form1.PagerStyle.NextPageText = "Go More >";
            Form1.PagerStyle.PreviousPageText = "< Go Prev";
        }
    }
    //</Snippet6>
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<body>
<!-- The first Form -->
    <mobile:Form ID="Form1" Runat="server" 
        Paginate="true" OnActivate="Form_Activate" 
        OnPaginated="Form_Paginated">
        <mobile:link ID="Link1" Runat="server" 
            NavigateUrl="#Form2">
            Go To Other Form
        </mobile:link>
        <mobile:Label ID="Label1" Runat="server">
            Welcome to ASP.NET
        </mobile:Label>
        <mobile:textview ID="txtView" Runat="server" />

        <mobile:DeviceSpecific ID="DevSpec" Runat="server">
            <Choice>
                <FooterTemplate>
                    <mobile:Label runat="server" id="lblCount" />
                </FooterTemplate>
            </Choice>
        </mobile:DeviceSpecific>
    </mobile:Form>
    
    <!-- The second Form -->
    <mobile:Form ID="Form2" Runat="server" 
        Paginate="true" OnPaginated="Form_Paginated">
        <mobile:Label ID="message2" Runat="server">
            Welcome to ASP.NET
        </mobile:Label>
        <mobile:link ID="Link2" Runat="server" 
            NavigateUrl="#Form1">Back</mobile:link>
    </mobile:Form>
</body>
</html>
<%@ Page Language="VB" 
    Inherits="System.Web.UI.MobileControls.MobilePage" %>
<%@ Register TagPrefix="mobile" 
    Namespace="System.Web.UI.MobileControls" 
    Assembly="System.Web.Mobile" %>
<%@ Import Namespace="System.Web.UI.MobileControls" %>
<%@ Import Namespace="System.Drawing" %>

<script runat="server">
    '<Snippet7>
    Private Sub Form_Activate(ByVal sender As Object, _
        ByVal e As EventArgs)
        
        Form1.Wrapping = Wrapping.NoWrap
        Dim a As String = "This is a very long string <br />"
        Dim b As String = "START "
        Dim i As Integer
        
        ' Create a long string to force pagination
        For i = 0 To 100
            b &= a
        Next
        
        txtView.Text = b & " END"
        Form1.ControlToPaginate = txtView
    End Sub
    '</Snippet7>

    '<Snippet5>
    Private Sub Form_Paginated(ByVal sender As Object, _
        ByVal e As EventArgs)
        
        ' Set the background color based on 
        ' the number of pages
        If ActiveForm.PageCount > 1 Then
            ActiveForm.BackColor = Color.LightBlue
        Else
            ActiveForm.BackColor = Color.LightGray
        End If
        
        ' Check to see if the Footer template has been chosen
        If DevSpec.HasTemplates Then
            Dim lbl As System.Web.UI.MobileControls.Label
            
            ' Get the Footer panel
            Dim pan As System.Web.UI.MobileControls.Panel = Form1.Footer

            ' Get the Label from the panel
            lbl = CType(pan.FindControl("lblCount"), System.Web.UI.MobileControls.Label)
            ' Set the text in the Label
            lbl.Text = "Page #" + Form1.CurrentPage.ToString()
        End If
    End Sub
    '</Snippet5>

    '<Snippet6>
    Private Sub Page_Load(ByVal sender As Object, _
        ByVal e As EventArgs)
        
        ' Set the pager text properties
        If Not IsPostBack Then
            Form1.PagerStyle.NextPageText = "Go Next >"
        Else
            ' For postback, set different text
            Form1.PagerStyle.NextPageText = "Go More >"
            Form1.PagerStyle.PreviousPageText = "< Go Prev"
        End If
    End Sub
    '</Snippet6>
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<body>
<!-- The first Form -->
    <mobile:Form ID="Form1" Runat="server" 
        Paginate="true" OnActivate="Form_Activate" 
        OnPaginated="Form_Paginated">
        <mobile:link ID="Link1" Runat="server" 
            NavigateUrl="#Form2">
            Go To Other Form
        </mobile:link>
        <mobile:Label ID="Label1" Runat="server">
            Welcome to ASP.NET
        </mobile:Label>
        <mobile:textview ID="txtView" Runat="server" />
        
        <mobile:DeviceSpecific ID="DevSpec" Runat="server">
            <Choice>
                <FooterTemplate>
                    <mobile:Label runat="server" id="lblCount" />
                </FooterTemplate>
            </Choice>
        </mobile:DeviceSpecific>

    </mobile:Form>
    
    <!-- The second Form -->
    <mobile:Form ID="Form2" Runat="server" 
        Paginate="true" OnPaginated="Form_Paginated">
        <mobile:Label ID="message2" Runat="server">
            Welcome to ASP.NET
        </mobile:Label>
        <mobile:link ID="Link2" Runat="server" 
            NavigateUrl="#Form1">Back</mobile:link>
    </mobile:Form>
</body>
</html>

Комментарии

Свойство ControlToPaginate позволяет одному элементу управления формы размежевать свое содержимое по нескольким представлениям на мобильных устройствах и обеспечивать следующую и предыдущую навигацию между представлениями. Элемент управления может разбить свое содержимое на страницы, даже если свойство содержащего Panel элемента управления Paginate имеет значение false.

Применяется к

См. также раздел