共用方式為


連結 ASP.NET Mobile Web 網頁

更新:2007 年 11 月

如果您在使用者控制項 (User Control) 所包含的控制項中,擁有 #form1 格式的連結, ResolveFormReference 方法便會在使用者控制項中查詢 ID 屬性設定為 form1 的表單。如果找不到該表單,方法便會進入巢狀使用者控制項的鏈結,然後在網頁上搜尋該表單。若要連結包含在使用者控制項中的表單,請使用下列語法來識別表單。

#mc1:form4

mc1 是使用者控制項的識別項 (Identifier)。冒號 (:) 會分隔表單的參考。

注意事項:

沒有項目錨點 (表單 page.aspx#element 的 URL,其中的 page 不是目前的網頁) 的任何支援。

範例

下列程式碼範例示範在表單之間巡覽。此範例包含一個 Mobile Web 網頁和一個行動使用者控制項。

Formtest.aspx

<%@ Page Language="C#" 
    Inherits="System.Web.UI.MobileControls.MobilePage" %>
<%@ Register TagPrefix="mobile" 
    Namespace="System.Web.UI.MobileControls" 
    Assembly="System.Web.Mobile" %>
<%@ Register TagPrefix="uc1" TagName="MobileWebUserControl1" 
    Src="formtest.ascx" %>
<script >
void Form_Activate(Object sender, EventArgs e)
{
    ((Form)sender).DataBind();
}
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<body>
  <mobile:form id="Form1"  
    OnActivate="Form_Activate">
    <mobile:Label ID="Label1"  
        Text='<%# "Current: " + ActiveForm.UniqueID %>' />
    <mobile:Link ID="Link1" href="#form2" 
        >Go to Form 2</mobile:Link>
    <mobile:Link ID="Link2" href="#form3" 
        >Go to Form 3</mobile:Link>
    <mobile:Link ID="Link3" href="#mc1:form4" 
        >Go to Form 4</mobile:Link>
   /mobile:form>

  <mobile:Form ID="Form2" Runat="server" 
      OnActivate="Form_Activate">
    <mobile:Label ID="Label2"  
        Text='<%# "Current: " + ActiveForm.UniqueID %>' />
    <mobile:Link ID="Link4" href="#form1" 
        >Go to Form 1</mobile:Link>
    <mobile:Link ID="Link5" href="#form3" 
        >Go to Form 3</mobile:Link>
    <mobile:Link ID="Link6" href="#mc1:form4" 
        >Go to Form 4</mobile:Link>
  </mobile:Form>

  <mobile:Form ID="Form3" Runat="server" 
      OnActivate="Form_Activate">
    <mobile:Label ID="Label3" Runat="server" 
        Text='<%# "Current: " + ActiveForm.UniqueID %>'>
    </mobile:Label>
    <mobile:Link ID="Link7" href="#form1"
        Runat="server" >Go to Form 1</mobile:Link>
    <mobile:Link ID="Link8" href="#form2"
        Runat="server" >Go to Form 2</mobile:Link>
    <mobile:Link ID="Link9" href="#mc1:form4"
        Runat="server" >Go to Form 4</mobile:Link>
  </mobile:Form>

  <uc1:MobileWebUserControl1 id="mc1"  />
</body>
</html>

Formtest.ascx

<%@ Control Language="C#" ClassName="FormTest" 
    Inherits="System.Web.UI.MobileControls.MobileUserControl" %>
<%@ Register TagPrefix="mobile" 
    Namespace="System.Web.UI.MobileControls" 
    Assembly="System.Web.Mobile" %>

<script >
void Form_Activate(Object sender, EventArgs e)
{
    ((Form)sender).DataBind();
}
</script>

<mobile:Form ID="Form4" Runat="server" OnActivate="Form_Activate">
  <mobile:Label ID="Label1"  
      Text='<%# "Current: " + 
        ((MobilePage)Page).ActiveForm.UniqueID %>' />
  <mobile:Link ID="Link1" href="#form1" 
      >Go to Form 1</mobile:Link>
  <mobile:Link ID="Link2" href="#form2" 
      >Go to Form 2</mobile:Link>
  <mobile:Link ID="Link3" href="#form3" 
      >Go to Form 3</mobile:Link>
  <mobile:Link ID="Link4" href="#form4a" 
      >Go to Form 4a</mobile:Link>
</mobile:Form>

<mobile:Form ID="Form4a" Runat="server" OnActivate="Form_Activate">
  <mobile:Label ID="Label"  
      Text='<%# "Current: " + 
        ((MobilePage)Page).ActiveForm.UniqueID %>' />
  <mobile:Link ID="Link5" href="#form1" 
      >Go to Form 1</mobile:Link>
  <mobile:Link ID="Link6" href="#form2" 
      >Go to Form 2</mobile:Link>
  <mobile:Link ID="Link7" href="#form3" 
       >Go to Form 3</mobile:Link>
  <mobile:Link ID="Link8" href="#form4" 
      >Go to Form 4</mobile:Link>
</mobile:Form>

請參閱

參考

AddLinkedForms

ResolveFormReference

其他資源

開發 ASP.NET Mobile Web 網頁

應用程式開發人員手冊