<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="MyBehavior.aspx.cs" Inherits="WebApplication1.MyBehavior" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>Behavior Testing!</title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="SM1" runat="server" />

    <script type="text/javascript">
      MyBehavior = function(element) {
        MyBehavior.initializeBase(this, [element]);
      };
      MyBehavior.prototype = {
        initialize: function() {
          MyBehavior.callBaseMethod(this, "initialize");
        },
        dispose: function() {
          MyBehavior.callBaseMethod(this, "dispose");
        }
      };
      MyBehavior.registerClass("MyBehavior", Sys.UI.Behavior);
    </script>

    <div id="MyDiv">
    </div>

    <script type="text/javascript">
      $create(
        MyBehavior, 
        {id: "Behavior1" }, 
        null, 
        null, 
        $get("MyDiv")
      );

      $create(
        MyBehavior, 
        {id: "Behavior2" }, 
        null, 
        null, 
        $get("MyDiv")
      );

      var myBehavior = Sys.UI.Behavior.getBehaviorByName($get("MyDiv"), "MyBehavior");
      alert (myBehavior.get_name());
      
      var behaviorsAssignedToDom = Sys.UI.Behavior.getBehaviors($get("MyDiv"));
      var behaviors = '';
      for (var i=0; i<behaviorsAssignedToDom.length; i++) {
        behaviors += behaviorsAssignedToDom[i].get_name() + " ";
      }
      
      alert (behaviors);

    </script>

    </form>
</body>
</html>
