Partager via


ActiveForm, propriété

Obtient ou définit le formulaire actif de la page.

public System.Web.UI.MobileControls.Form ActiveForm {
   get,
   set
}

Notes

Lorsqu'une page est initialement affichée, le premier formulaire de la page devient automatiquement actif. Lors des publications ultérieures, un autre formulaire peut devenir actif, soit par définition par programme de cette propriété, soit comme résultat de la navigation de l'utilisateur par l'intermédiaire d'un contrôle Link.

Exemple

L'exemple suivant montre comment utiliser la propriété ActiveForm d'un contrôle Form. La propriété ActiveForm est définie dans le clic de bouton. Cette technique est utile lorsque plusieurs pages sont impliquées dans une application et qu'elles partagent des variables de session.

<script language=vb runat="server">

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 
   
   If Not IsPostBack
       Session("formid") = "0"
   End If
   
   If (Session("formid") = "0")
   
       ActiveForm = Form1
       Session("formid") = "1"
   
   Else If (Session("formid") = "1")
   
       ActiveForm = Form2
       Session("formid") = "0"
       
   End If

End Sub 

     </script>
<mobile:form id="Form1" runat=server >
  <mobile:label id=Label1 runat=server Text="Welcome 1"/>
  <mobile:Command runat=server Text="Go to Form2"  />
</mobile:form>

<mobile:form id="Form2" runat=server >
  <mobile:label id=Label2 runat=server Text="Welcome 2"/>
  <mobile:Command runat=server Text="Go to Form1"  />
</mobile:form>


[C#]
<script language="c#" runat=server>
private void Page_Load(object sender, System.EventArgs e)
{
   if(!IsPostBack)
      Session["formid"] = "0";

   if(Session["formid"] == "0")
   {
      ActiveForm = Form1;
      Session["formid"] = "1";
   }
   else if(Session["formid"] == "1")
   {
      ActiveForm = Form2;
      Session["formid"] = "0";
   }
}

</script>

<mobile:form id="Form1" runat=server >
  <mobile:label id=Label1 runat=server Text="Welcome 1"/>
  <mobile:Command runat=server Text="Go to Form2"  />
</mobile:form>

<mobile:form id="Form2" runat=server >
  <mobile:label id=Label2 runat=server Text="Welcome 2"/>
  <mobile:Command runat=server Text="Go to Form1"  />
</mobile:form>

Voir aussi

S'applique à : MobilePage, classe