<%@ Page Language="C#" %>

<!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>ASP.NET AJAX</title>

  <script language="JavaScript" type="text/javascript">
  function pageLoad() {
    var textbox = new Sys.Preview.UI.TextBox($get("TextBox1"));
    var label = new Sys.Preview.UI.Label($get("Label1"));

    var binding = new Sys.Preview.Binding();
    binding.set_dataContext(textbox);
    binding.set_dataPath("text");
    binding.set_property("text");
    binding.add_transform(customHtmlEncode);
    binding.set_target(label);

    textbox.initialize();
    label.initialize();
    binding.initialize();
  }

  function customHtmlEncode(sender, args) {
    var value = args.get_value();
    var newValue = value.replace(/&/g, "&amp;")
                        .replace(/</g, "&lt;")
                        .replace(/>/g, "&gt;")
                        .replace(/"/g, "&quot;")
                        .replace(/’/g, "&apos;");
    args.set_value(newValue);
  }
  </script>

</head>
<body>
  <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
      <Scripts>
        <asp:ScriptReference Name="PreviewScript.js" Assembly="Microsoft.Web.Preview" />
      </Scripts>
    </asp:ScriptManager>
    <div>
      <input type="text" id="TextBox1" /><br />
      <label id="Label1"></label>
    </div>
  </form>
</body>
</html>
