<%@ 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 runat="server">
  <title>ASP.NET AJAX</title>
  <script type="text/javascript">
   function pageLoad() {
     $addHandler(
       $get("txtUsername"),
       "change",
       saveProfile);
     Sys.Services.ProfileService.load(
       "", 
       profileLoaded,
       profileError, 
       "odczytać");
   }
   
   function profileLoaded() {
     $get("statusText").firstChild.nodeValue = "Profil załadowany.";
     if (Sys.Services.ProfileService.properties.userName != null) {
       $get("txtUsername").value = Sys.Services.ProfileService.properties.userName;
     }
   }
   
   function profileError(result, context) {
     $get("statusText").firstChild.nodeValue = 
       "Nie można " + context + " profilu (" + 
       result.get_message() + 
       "). Sprawdź konfigurację pliku web.config!";
   }
   
   function saveProfile() {
     Sys.Services.ProfileService.properties.userName = $get("txtUsername").value;
     Sys.Services.ProfileService.save(
       null, 
       profileSaved,
       profileError,
       "zapisać");
   }
   
   function profileSaved() {
     $get("statusText").firstChild.nodeValue = "Profil zapisany.";
   }
   
  </script>
</head>
<body>
  <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server" />
    <div>
      Nazwa użytkownika: <input type="text" id="txtUsername" runat="server" /><br />
      Hasło: <input type="password" id="txtPassword" runat="server" /><br />
      <input type="button" id="Button1" runat="server" value="Zaloguj" 
        onclick="alert('nie zaimplementowane!');" /><br />
      <span id="statusText" runat="server">&nbsp;</span>
    </div>
  </form>
</body>
</html>
