ASP.Net/Mobile Control/Mobile Capabilities

Материал из .Net Framework эксперт
Версия от 11:52, 26 мая 2010; Admin (обсуждение | вклад) (1 версия)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

Get mobile device code Capabilities (VB.net)

<%@ Page 
    Inherits="System.Web.UI.MobileControls.MobilePage" 
    Language="VB" 
%>
<%@ Register 
    TagPrefix="mobile" 
    Namespace="System.Web.UI.MobileControls" 
    Assembly="System.Web.Mobile" 
%>
<script runat="server" language="VB">
Sub Page_Load(ByVal Sender as Object, ByVal E as EventArgs)
    Dim MyMobCaps as Mobile.MobileCapabilities
    MyMobCaps = Request.Browser
    If MyMobCaps.IsColor Then
        Image1.ImageURL="color.gif"
    Else
        Image1.ImageURL="nocolor.gif"
    End If
End Sub
</script>
<mobile:Form id="Test" runat="server">
    <mobile:Image 
        runat="server" 
        id="Image1"
        AlternateText="No graphics supported!">
    </mobile:Image>
</mobile:Form>



Get mobile device information (VB.net)

<%@ Page 
    Inherits="System.Web.UI.MobileControls.MobilePage" 
    Language="VB" 
%>
<%@ Register 
    TagPrefix="mobile" 
    Namespace="System.Web.UI.MobileControls" 
    Assembly="System.Web.Mobile" 
%>
<script runat="server" language="VB">
Sub Page_Load(ByVal Sender as Object, ByVal E as EventArgs)
    Dim MyMobCaps as Mobile.MobileCapabilities
    MyMobCaps = Request.Browser
    Label1.Text = "Mobile Device?: " _
        & MyMobCaps.IsMobileDevice _
        & " Mobile Device Model: " _
        & MyMobCaps.MobileDeviceModel _
        & " Mobile Device Manufacturer: " _
        & MyMobCaps.MobileDeviceManufacturer
End Sub
</script>
<mobile:Form id="Test" runat="server">
    <mobile:label
        runat="server" 
        id="Label1"
    />
</mobile:Form>



Get mobile device screen width and height (VB.net)

<%@ Page 
    Inherits="System.Web.UI.MobileControls.MobilePage" 
    Language="VB" 
%>
<%@ Register 
    TagPrefix="mobile" 
    Namespace="System.Web.UI.MobileControls" 
    Assembly="System.Web.Mobile" 
%>
<script runat="server" language="VB">
Sub Page_Load(ByVal Sender as Object, ByVal E as EventArgs)
    Dim MyMobCaps as Mobile.MobileCapabilities
    MyMobCaps = Request.Browser
    Label1.Text = "Screen Width: " _
        & MyMobCaps.ScreenPixelsWidth _
        & " Screen Height: " _
        & MyMobCaps.ScreenPixelsHeight
End Sub
</script>
<mobile:Form id="Test" runat="server">
    <mobile:label
        runat="server" 
        id="Label1"
    />
</mobile:Form>



Mobile Capabilities

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Hello" %>
<%@ Register TagPrefix="mobile" Namespace="System.Web.UI.MobileControls" Assembly="System.Web.Mobile" %>
<%@ Import Namespace="System.Web.Mobile" %>
<html xmlns="http://www.w3.org/1999/xhtml" >
<body>
    <mobile:Form ID="Form1" runat="server">
        Language is
        <mobile:Label runat="server" font-bold="true" id="theBrowser" />
    </mobile:Form>
</body>
</html>
File: Default.aspx.cs
using System;
using System.Collections;
using System.ruponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.Mobile;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.MobileControls;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
public partial class Hello : System.Web.UI.MobileControls.MobilePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        MobileCapabilities mobCaps = (MobileCapabilities)Request.Browser;
        theBrowser.Text = mobCaps.PreferredRenderingType;
    }
}



Mobile Capabilities: support color? (VB.net)

<%@ Page 
    Inherits="System.Web.UI.MobileControls.MobilePage" 
    Language="VB" 
%>
<%@ Register 
    TagPrefix="mobile" 
    Namespace="System.Web.UI.MobileControls" 
    Assembly="System.Web.Mobile" 
%>
<script runat="server" language="VB">
Sub Page_Load(ByVal Sender as Object, ByVal E as EventArgs)
    Dim MyMobCaps as Mobile.MobileCapabilities
    MyMobCaps = Request.Browser
    If MyMobCaps.IsColor Then
        Image1.ImageURL="color.gif"
    Else
        Image1.ImageURL="nocolor.gif"
    End If
End Sub
</script>
<mobile:Form id="Test" runat="server">
    <mobile:Image 
        runat="server" 
        id="Image1"
        AlternateText="Your device does not support graphics!">
    </mobile:Image>
</mobile:Form>



Preferred RenderingType

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Paginate" %>
<%@ Register TagPrefix="mobile" Namespace="System.Web.UI.MobileControls" Assembly="System.Web.Mobile" %>
<%@ Import Namespace="System.Web.Mobile" %>
<html xmlns="http://www.w3.org/1999/xhtml" >
<body>
    <mobile:Form ID="Form1" runat="server" Paginate="True">
        Language is
        <mobile:Label runat="server" font-bold="true" id="theBrowser" />
        Item #1 <br />
        Item #2 <br />
        Item #3 <br />
        Item #4 <br />
        Item #5 <br />
        Item #6 <br />
        Item #7 <br />
        Item #8 <br />
        Item #9 <br />
        Item #10 <br />
        Item #11 <br />
        Item #12 <br />
    </mobile:Form>
</body>
</html>
File: Default.aspx.cs
using System;
using System.Collections;
using System.ruponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.Mobile;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.MobileControls;
using System.Web.UI.WebControls;

public partial class Paginate : System.Web.UI.MobileControls.MobilePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        MobileCapabilities mobCaps = (MobileCapabilities)Request.Browser;
        theBrowser.Text = mobCaps.PreferredRenderingType;
    }
}