Deactivate イベント

アクティブ フォームが非アクティブになったときに発生します。

public event EventHandler Deactivate

解説

フォームが非アクティブになるのは、次のいずれかの場合です。

  • プログラムからページの ActiveForm プロパティがほかのフォームに設定された場合。
  • フォームをターゲットとする Link コントロールを通じてユーザーがほかのフォームに移動した場合。

上のいずれかの動作が実行されない限り、アクティブ フォームが Deactivate イベントを受け取ることはありません。イベント チェイン内におけるこのイベントの位置は、子コントロール、データ セット、またはグローバル変数をリセットするときに特に重要になります。

サンプル

次のサンプルは、Deactivate イベントをトラップして SelectionList をクリアする方法を示しています。

[Visual Basic]

<SCRIPT language="vb" runat="server">

Class Task
   Private _TaskName As String
   Private _Status As String
   
   
   Public Sub New(TaskName As String, Status As String)
      _TaskName = TaskName
      _Status = Status
   End Sub
   
   
   Public ReadOnly Property TaskName() As String
      Get
         Return _TaskName
      End Get
   End Property
   
   Public ReadOnly Property Status() As String
      Get
         Return _Status
      End Get
   End Property 
End Class

 ' Persist across multiple postbacks.
Public Shared count As Integer = 0

Dim arr As ArrayList


Sub Form_Activate(sender As Object, e As EventArgs)
   
   If count = 0 Then
      message2.Text = "welcome Welcome to Form Sample"
   Else
      message2.Text = "you You r viewing viewed this Form " +(count + 1).ToString() + " times."
   End If
   
   myForm.Alignment = System.Web.UI.MobileControls.Alignment.Center
   myForm.Wrapping = System.Web.UI.MobileControls.Wrapping.NoWrap
   myForm.BackColor = System.Drawing.Color.LightBlue
   myForm.ForeColor = System.Drawing.Color.Blue
   myForm.Paginate = True
   ' When the user clicks the submit button, switch forms.
   myForm.Action = "newpage.aspx"
   If Not IsPostBack Then
      SelectionList1.DataValueField = "Status"
      SelectionList1.DataTextField = "TaskName"
      
      ' Create an array and add the tasks to it.
      arr = New ArrayList()
      arr.Add(New Task("Verify transactions", "Done"))
      arr.Add(New Task("Check balance sheet", "Scheduled"))
      arr.Add(New Task("Send report", "Pending"))
      
      ' Associate and bind the SelectionList object to the array.
      SelectionList1.DataSource = arr
      SelectionList1.DataBind()
   End If
End Sub


Sub Form_Deactivate(sender As Object, e As EventArgs)
   SelectionList1.Items.Clear()
   count += 1
End Sub


Sub Form2_Activate(sender As Object, e As EventArgs)
   yourForm.BackColor = System.Drawing.Color.Black
   yourForm.ForeColor = System.Drawing.Color.White
End Sub


</SCRIPT>

<mobile:form id="myForm" runat=server OnActivate="Form_Activate"
   OnDeactivate="Form_Deactivate">
   <mobile:label id="message1" runat=server>
      Welcome to ASP.NET
   </mobile:label> 
   <mobile:label id="message2" runat=server></mobile:label>
   <mobile:SelectionList runat=server id="SelectionList1" 
      ForeColor=red SelectType=CheckBox/>
   <mobile:link id="link1" runat=server NavigateUrl=#yourForm 
      Text="Next Form"></mobile:link><br/><br/>
   <mobile:Command runat=server Text="Submit" />
</mobile:form>

<mobile:form id="yourForm" runat=server OnActivate="Form2_Activate">
   <mobile:label id="message4" runat=server>
      Welcome to ASP.NET
   </mobile:label> 
   <mobile:link id="link2" runat=server NavigateUrl=#myForm Text="Back"/>
</mobile:form>
<script language="c#" runat=server>

class Task
{
   private String _TaskName;
   private String _Status;

   public Task(String TaskName, String Status) 
   { 
      _TaskName = TaskName; 
      _Status = Status;
   }

   public String TaskName { get { return _TaskName; } }
   public String Status { get { return _Status; } }
}

// Persist across multiple postbacks.
public static int count = 0;

ArrayList arr;
void Form_Activate(object sender, EventArgs e)
{

   if (count==0)
      message2.Text = "Welcome to Form Sample";
   else
      message2.Text = "You viewed this Form "
        + (count+1) + " times.";

   myForm.Alignment=System.Web.UI.MobileControls.Alignment.Center;
   myForm.Wrapping=System.Web.UI.MobileControls.Wrapping.NoWrap;
   myForm.BackColor = System.Drawing.Color.LightBlue; 
   myForm.ForeColor = System.Drawing.Color.Blue;  
   myForm.Paginate = true;
   // When the user clicks the submit button, switch forms.
   myForm.Action = "newpage.aspx";

   SelectionList1.DataValueField="Status";
   SelectionList1.DataTextField="TaskName";

   // Create an array and add the tasks to it.
   arr = new ArrayList();
   arr.Add (new Task ("Verify transactions", "Done"));
   arr.Add (new Task ("Check balance sheet", "Scheduled"));
   arr.Add (new Task ("Send report", "Pending"));

   // Associate and bind the SelectionList object to the array.
   SelectionList1.DataSource = arr;
   SelectionList1.DataBind ();

}

void Form_Deactivate(object sender, EventArgs e)
{   
   SelectionList1.Items.Clear();
   count++;         
}

void Form2_Activate(object sender, EventArgs e)
{
   yourForm.BackColor = System.Drawing.Color.Black; 
   yourForm.ForeColor = System.Drawing.Color.White; 
}

</script>

<mobile:form id="myForm" runat=server OnActivate="Form_Activate"
   OnDeactivate="Form_Deactivate">
   <mobile:label id="message1" runat=server>
      Welcome to ASP.NET
   </mobile:label> 
   <mobile:label id="message2" runat=server></mobile:label>
   <mobile:SelectionList runat=server id="SelectionList1" 
      ForeColor=red SelectType=CheckBox/>
   <mobile:link id="link1" runat=server NavigateUrl=#yourForm 
      Text="Next Form"></mobile:link><br/><br/>
   <mobile:Command runat=server Text="Submit" />
</mobile:form>

<mobile:form id="yourForm" runat=server OnActivate="Form2_Activate">
   <mobile:label id="message4" runat=server>
      Welcome to ASP.NET
   </mobile:label> 
   <mobile:link id="link2" runat=server NavigateUrl=#myForm Text="Back"/>
</mobile:form>

参照

Activate イベント | OnDeactivate メソッド

Form クラス