This documentation is archived and is not being maintained.

HtmlInputCheckBox.ServerChange Event

Occurs when the Web page is submitted to the server and the HtmlInputCheckBox control changes state from the previous post.

[Visual Basic]
Public Event ServerChange As EventHandler
[C#]
public event EventHandler ServerChange;
[C++]
public: __event EventHandler* ServerChange;

[JScript] In JScript, you can handle the events defined by a class, but you cannot define your own.

Event Data

The event handler receives an argument of type EventArgs.

Remarks

This event is raised when the Web page is submitted to the server and the state of the HtmlInputCheckBox control changes state from the previous post.

Note   The control must have viewstate enabled for the ServerChange event to work correctly.

For more information about handling events, see Consuming Events.

Example

[Visual Basic, C#, JScript] The following example demonstrates how to specify and code a handler for the ServerChange event.

[Visual Basic] 
<%@ Page Language="VB" AutoEventWireup="True" %>

<html>
<head>

   <script language="VB" runat="server">

    Sub Button1_Click(sender As Object, e As EventArgs)
        
        If Prev_Check_State.InnerHtml = Check1.Checked.ToString() Then
            Span2.InnerHtml = "CheckBox1 did not change state between clicks."
        End If 
        If Check1.Checked = True Then
            Span1.InnerHtml = "CheckBox1 is checked!"
            Prev_Check_State.InnerHtml = "True"
        Else
            Span1.InnerHtml = "CheckBox1 is not checked!"
            Prev_Check_State.InnerHtml = "False"
        End If
    End Sub 'Button1_Click
     

    Sub Server_Changed(sender As Object, e As EventArgs)
        Span2.InnerHtml = "CheckBox1 changed state between clicks."
    End Sub 'Server_Changed

  </script>

</head>

<body>

   <h3>HtmlInputCheckBox Sample</h3>

   <form runat=server>

      <input id="Check1" 
             type="checkbox"
             OnServerChange="Server_Changed" 
             runat="server"/> 
 
      CheckBox1 &nbsp;&nbsp;

      <span id="Span1" 
            style="color:red" 
            runat="server"/>

      <p>

      <input type="button" 
             id="Button1" 
             value="Enter" 
             OnServerClick="Button1_Click" 
             runat="server"/>
      
      <br><br>

      <span id="Span2" 
            runat="server"/>

      <htmlinputhidden id="Prev_Check_State"
                       Visible="false"
                       runat="server"/>

   </form>

</body>
</html>
   

[C#] 
<%@ Page Language="C#" AutoEventWireup="True" %>

<html>
<head>

   <script language="C#" runat="server">

      void Button1_Click(object sender, EventArgs e) 
      { 

         if (Prev_Check_State.InnerHtml == Check1.Checked.ToString())
            Span2.InnerHtml = "CheckBox1 did not change state between clicks.";

         if (Check1.Checked == true)
         {          
            Span1.InnerHtml = "CheckBox1 is checked!";
            Prev_Check_State.InnerHtml="True";
         }         
         else
         { 
            Span1.InnerHtml = "CheckBox1 is not checked!";
            Prev_Check_State.InnerHtml="False";
         }
         
      }

      void Server_Changed(object sender, EventArgs e) 
      {
         Span2.InnerHtml = "CheckBox1 changed state between clicks.";
      }

   </script>

</head>

<body>

   <h3>HtmlInputCheckBox Sample</h3>

   <form runat=server>

      <input id="Check1" 
             type="checkbox"
             OnServerChange="Server_Changed" 
             runat="server"/> 
 
      CheckBox1 &nbsp;&nbsp;

      <span id="Span1" 
            style="color:red" 
            runat="server"/>

      <p>

      <input type="button" 
             id="Button1" 
             value="Enter" 
             OnServerClick="Button1_Click" 
             runat="server"/>
      
      <br><br>

      <span id="Span2" 
            runat="server"/>

      <htmlinputhidden id="Prev_Check_State"
                       Visible="false"
                       runat="server"/>

   </form>

</body>
</html>
   

[JScript] 
<%@ Page Language="JScript" AutoEventWireup="True" %>

<html>
<head>

   <script language="JSCRIPT" runat="server">

    function Button1_Click(sender : Object, e : EventArgs){
        
        if(Prev_Check_State.InnerHtml == Check1.Checked.ToString())
            Span2.InnerHtml = "CheckBox1 did not change state between clicks."
        if(Check1.Checked){
            Span1.InnerHtml = "CheckBox1 is checked!"
            Prev_Check_State.InnerHtml = "True"
        }else{
            Span1.InnerHtml = "CheckBox1 is not checked!"
            Prev_Check_State.InnerHtml = "False"
        }
    }

    function Server_Changed(sender : Object, e : EventArgs){
        Span2.InnerHtml = "CheckBox1 changed state between clicks."
    }

  </script>

</head>

<body>

   <h3>HtmlInputCheckBox Sample</h3>

   <form runat=server>

      <input id="Check1" 
             type="checkbox"
             OnServerChange="Server_Changed" 
             runat="server"/> 
 
      CheckBox1 &nbsp;&nbsp;

      <span id="Span1" 
            style="color:red" 
            runat="server"/>

      <p>

      <input type="button" 
             id="Button1" 
             value="Enter" 
             OnServerClick="Button1_Click" 
             runat="server"/>
      
      <br><br>

      <span id="Span2" 
            runat="server"/>

      <htmlinputhidden id="Prev_Check_State"
                       Visible="false"
                       runat="server"/>

   </form>

</body>
</html>
   

[C++] No example is available for C++. To view a Visual Basic, C#, or JScript example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

HtmlInputCheckBox Class | HtmlInputCheckBox Members | System.Web.UI.HtmlControls Namespace | OnServerChange

Show: