<%@ 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 validateSquare(sender, args) {
    var value = args.get_value();
    args.set_isValid(Math.sqrt(value) == Math.floor(Math.sqrt(value)));
  }
  </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>
      Cokolowiek: <input type="text" id="TextBox1" />
      <span id="Error1" style="color: red;">*</span>
      <br />
      Druga potęga: <input type="text" id="TextBox2" />
      <span id="Error2" style="color: red;">*</span>
      <br />
      <input type="submit" />
    </div>
    <div id="Errors">-brak błędów-</div>
  </form>
  <script type="text/xml-script">
    <page xmlns:script="http://schemas.microsoft.com/xml-script/2005">
      <components>
        <textBox id="TextBox1">
          <validators>
            <requiredFieldValidator errorMessage="** brak wartości w polu TextBox1" />
          </validators>
        </textBox>
        <validationErrorLabel id="Error1"
                              associatedControl="TextBox1" />
        <textBox id="TextBox2">
          <validators>
            <requiredFieldValidator errorMessage="** brak wartości w polu TextBox2" />
            <typeValidator type="Number" errorMessage="** tylko cyfry" />
            <customValidator validateValue="validateSquare" errorMessage="** tylko druga potęga" />
          </validators>
        </textBox>
        <validationErrorLabel id="Error2"
                              associatedControl="TextBox2" />
        <validationGroup id="group">
          <associatedControls>
            <reference component="TextBox1" />
            <reference component="TextBox2" />
          </associatedControls>
        </validationGroup>
        <label id="Errors">
          <bindings>
            <binding dataContext="group" dataPath="isValid" property="visible" />
          </bindings>
        </label>
      </components>
    </page>
  </script>
</body>
</html>
