DeviceSpecific イベント

名前 | 説明 | |
---|---|---|
![]() | DataBinding | デザイン時にデータ バインド式が作成されると発生します。 |
![]() | Disposed | サーバー コントロールがメモリから解放されると発生します。これは、ASP.NET ページが要求されている場合のサーバー コントロールの有効期間における最終段階です。 |
![]() | Init | コントロールが初期化されると発生します。これは、コントロールの有効期間における最初の手順です。 |
![]() | Load | サーバー コントロールが Page オブジェクトに読み込まれると発生します。 |
![]() | PreRender | コントロールが格納している MobilePage オブジェクトをレンダリングしようとすると発生します。 |
![]() | Unload | サーバー コントロールがメモリからアンロードされると発生します。 |

DeviceSpecific クラス
アセンブリ: System.Web.Mobile (system.web.mobile.dll 内)


<DeviceSpecific> 要素内には、通常、1 つ以上の <Choice> 要素を指定します。各 <Choice> 要素には、対象デバイスの機能に対応した選択項目の評価方法を指定する属性を含めます。実行時に、各選択項目が順番に評価され、評価が最初に成立した項目が使用されます。DeviceSpecific の Choice コンストラクトは、テンプレート セットを指定し、プロパティをオーバーライドするために使用されます。たとえば、Image コントロールにデバイス固有のイメージを指定するために使用できます。
![]() |
---|
DeviceSpecific クラスは Web フォームの System.Web.UI.Control 名前空間から継承するものですが、これは単なる実装詳細です。<Choice> は、コントロールのようには動作しません。 |

DeviceSpecific オブジェクトと DeviceSpecificChoice オブジェクトを使用して、さまざまなデバイスに固有のインターフェイスをモバイル形式で作成する方法を次のコード例に示します。
![]() |
---|
次のコード サンプルはシングルファイル コード モデルを使用しており、分離コード ファイルに直接コピーされた場合は正常に動作しない可能性があります。このコード サンプルは、拡張子が .aspx の空のテキスト ファイルにコピーする必要があります。詳細については、「ASP.NET Web ページのコード モデル」を参照してください。 |
<%@ Page Language="VB" Inherits="System.Web.UI.MobileControls.MobilePage" %> <%@ Register TagPrefix="mobile" Namespace="System.Web.UI.MobileControls" Assembly="System.Web.Mobile" %> <script runat="server"> Private Sub Form_Init(ByVal sender As Object, ByVal e As EventArgs) ' Create a DeviceSpecific group for Choice elements Dim devSpecific As New DeviceSpecific() Dim ipa As IParserAccessor ' Create two Choice objects, one with a filter For i As Integer = 0 To 1 Dim devChoice As DeviceSpecificChoice Dim custTemplate As ITemplate ' Create a Choice object devChoice = New DeviceSpecificChoice() ' Only the first Choice has a filter (must be in Web.config) If i = 0 Then devChoice.Filter = "isHTML32" ' Create the header template. custTemplate = New CustomTemplate("HeaderTemplate") ' Put header template in a new container custTemplate.InstantiateIn(New TemplateContainer()) ' Add the header template to the Choice devChoice.Templates.Add("HeaderTemplate", custTemplate) ' Create the footer template custTemplate = New CustomTemplate("FooterTemplate") ' Put footer template in a new container custTemplate.InstantiateIn(New TemplateContainer()) ' Add the footer template to the Choice devChoice.Templates.Add("FooterTemplate", custTemplate) End If ' Add the Choice to the DeviceSpecific ipa = CType(devSpecific, IParserAccessor) ipa.AddParsedSubObject(devChoice) Next ' Add the DeviceSpecific object to the form ipa = CType(Form1, IParserAccessor) ipa.AddParsedSubObject(devSpecific) End Sub Protected Sub Page_Load(ByVal sender As Object, _ ByVal e As EventArgs) Dim lab As System.Web.UI.MobileControls.Label lab = CType(Form1.Header.FindControl("Label1"), _ System.Web.UI.MobileControls.Label) If IsNothing(lab) Then Return ' Get the selected choice's filter name Dim filterName As String = _ Form1.DeviceSpecific.SelectedChoice.Filter If filterName = "isHTML32" Then lab.Text += " - HTML32" Else lab.Text += " - Default" End If End Sub Public Class CustomTemplate Implements ITemplate Dim templName As String ' Constructor Public Sub New(ByVal TemplateName As String) templName = TemplateName End Sub Public Sub InstantiateIn(ByVal container As Control) _ Implements ITemplate.InstantiateIn If templName = "HeaderTemplate" Then ' Create a label Dim lab As New System.Web.UI.MobileControls.Label lab.Text = "Header Template" lab.ID = "Label1" ' Create a command Dim cmd As New Command() cmd.Text = "Submit" ' Add controls to the container container.Controls.Add(lab) container.Controls.Add(cmd) ElseIf templName = "FooterTemplate" Then ' Create a label Dim lab As System.Web.UI.MobileControls.Label lab = New System.Web.UI.MobileControls.Label() lab.ID = "Label2" lab.Text = "Footer Template" ' Add label to the container container.Controls.Add(lab) End If End Sub End Class </script> <html xmlns="http:'www.w3.org/1999/xhtml" > <body> <mobile:form id="Form1" runat="server" OnInit="Form_Init"> </mobile:form> </body> </html>
<%@ Page Language="C#" Inherits="System.Web.UI.MobileControls.MobilePage" %> <%@ Register TagPrefix="mobile" Namespace="System.Web.UI.MobileControls" Assembly="System.Web.Mobile" %> <script runat="server"> private void Form_Init(object sender, System.EventArgs e) { // Create a DeviceSpecific group for Choice elements DeviceSpecific devSpecific = new DeviceSpecific(); // Create two Choice objects, one with a filter for (int i = 0; i < 2; i++) { DeviceSpecificChoice devChoice; ITemplate custTemplate; // Create a Choice object devChoice = new DeviceSpecificChoice(); // Only the first Choice has a filter (must be in Web.config) if (i == 0) devChoice.Filter = "isHTML32"; // Create the header template. custTemplate = new CustomTemplate("HeaderTemplate"); // Put header template in a new container custTemplate.InstantiateIn(new TemplateContainer()); // Add the header template to the Choice devChoice.Templates.Add("HeaderTemplate", custTemplate); // Create the footer template custTemplate = new CustomTemplate("FooterTemplate"); // Put footer template in a new container custTemplate.InstantiateIn(new TemplateContainer()); // Add the footer template to the Choice devChoice.Templates.Add("FooterTemplate", custTemplate); // Add the Choice to the DeviceSpecific ((IParserAccessor)devSpecific).AddParsedSubObject(devChoice); } // Add the DeviceSpecific object to the form ((IParserAccessor)Form1).AddParsedSubObject(devSpecific); } protected void Page_Load(object sender, EventArgs e) { System.Web.UI.MobileControls.Label lab; lab = (System.Web.UI.MobileControls.Label)Form1.Header.FindControl("Label1"); if (lab == null) return; // Get the selected choice's filter name string filterName = Form1.DeviceSpecific.SelectedChoice.Filter; if (filterName == "isHTML32") lab.Text += " - HTML32"; else lab.Text += " - Default"; } public class CustomTemplate : ITemplate { String templateName; // Constructor public CustomTemplate(string TemplateName) { templateName = TemplateName; } public void InstantiateIn(Control container) { if (templateName == "HeaderTemplate") { // Create a label System.Web.UI.MobileControls.Label lab; lab = new System.Web.UI.MobileControls.Label(); lab.Text = "Header Template"; lab.ID = "Label1"; // Create a command Command cmd = new Command(); cmd.Text = "Submit"; // Add controls to the container container.Controls.Add(lab); container.Controls.Add(cmd); } else if (templateName == "FooterTemplate") { // Create a label System.Web.UI.MobileControls.Label lab; lab = new System.Web.UI.MobileControls.Label(); lab.ID = "Label2"; lab.Text = "Footer Template"; // Add label to the container container.Controls.Add(lab); } } } </script> <html > <body> <mobile:form id="Form1" runat="server" OnInit="Form_Init"> </mobile:form> </body> </html>
上記のコードはすべて、宣言によって次のマークアップと置換できます。
<html > <body> <mobile:Form id="Form1" runat="server"> <mobile:DeviceSpecific Runat="server"> <Choice Filter="isHTML32"> <HeaderTemplate> <mobile:Label ID="Label1" Runat="server"> Header Template - HTML32</mobile:Label> <mobile:Command Runat="server"> Submit</mobile:Command> </HeaderTemplate> <FooterTemplate> <mobile:Label ID="Label2" Runat="server"> Footer Template</mobile:Label> </FooterTemplate> </Choice> <Choice> <HeaderTemplate> <mobile:Label ID="Label1" Runat="server"> Header Template - Default</mobile:Label> <mobile:Command ID="Command1" Runat="server"> Submit</mobile:Command> </HeaderTemplate> <FooterTemplate> <mobile:Label ID="Label2" Runat="server"> Footer Template</mobile:Label> </FooterTemplate> </Choice> </mobile:DeviceSpecific> </mobile:Form> </body> </html>


System.Web.UI.Control
System.Web.UI.MobileControls.DeviceSpecific


Windows 98, Windows 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
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


DeviceSpecific コンストラクタ
アセンブリ: System.Web.Mobile (system.web.mobile.dll 内)


Windows 98, Windows 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
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


DeviceSpecific プロパティ



DeviceSpecific メソッド



DeviceSpecific メンバ
<DeviceSpecific> 要素内にある複数の代替コンテンツからどれを選択するかを指定するコンストラクトを提供します。
DeviceSpecific データ型で公開されるメンバを以下の表に示します。

名前 | 説明 | |
---|---|---|
![]() | DeviceSpecific |





名前 | 説明 | |
---|---|---|
![]() | DataBinding | デザイン時にデータ バインド式が作成されると発生します。 |
![]() | Disposed | サーバー コントロールがメモリから解放されると発生します。これは、ASP.NET ページが要求されている場合のサーバー コントロールの有効期間における最終段階です。 |
![]() | Init | コントロールが初期化されると発生します。これは、コントロールの有効期間における最初の手順です。 |
![]() | Load | サーバー コントロールが Page オブジェクトに読み込まれると発生します。 |
![]() | PreRender | コントロールが格納している MobilePage オブジェクトをレンダリングしようとすると発生します。 |
![]() | Unload | サーバー コントロールがメモリからアンロードされると発生します。 |

- DeviceSpecificのページへのリンク