<%@ 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 type="text/javascript">
   function pageLoad() {
     $addHandler(
       $get("txtUsername"),
       "change",
       saveProfile1);
     $addHandler(
       $get("txtPassword"),
       "change",
       saveProfile2);
     Sys.Services.ProfileService.load(
       "", 
       profileLoaded,
       profileError, 
       {"operation": "odczytać"});
   }
   
   function profileLoaded() {
     if (Sys.Services.ProfileService.properties.UserData != null) {
       $get("statusText").firstChild.nodeValue = "Profil załadowany.";
       $get("txtUsername").value = Sys.Services.ProfileService.properties.UserData.myUserName;
       $get("txtPassword").value = Sys.Services.ProfileService.properties.UserData.myPassword;
     } else {
       $get("statusText").firstChild.nodeValue = "Brak danych."; 
     }
   }
   
   function profileError(result, context) {
     $get("statusText").firstChild.nodeValue = 
       "Nie można " + context.operation + " profilu (" + 
       result.get_message() + 
       "). Sprawdź konfigurację pliku web.config!";
   }
   
   function saveProfile1() {
     Sys.Services.ProfileService.properties.UserData.myUserName = $get("txtUsername").value;
     Sys.Services.ProfileService.save(
       null, 
       profileSaved,
       profileError,
       {"operation": "zapisać", "property": "nazwa użytkownika"});
   }

   function saveProfile2() {
     Sys.Services.ProfileService.properties.UserData.myPassword = $get("txtPassword").value;
     Sys.Services.ProfileService.save(
       null, 
       profileSaved,
       profileError,
       {"operation": "zapisać", "property": "hasło"});
   }
   
   function profileSaved(success, context) {
     $get("statusText").firstChild.nodeValue = "Parametr " + context.property + " został zapisany w profilu.";
   }
   
  </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>
