PageMethod.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // PageMethods.js
  2. var displayElement;
  3. // Initializes global variables and session state.
  4. function pageLoad()
  5. {
  6. displayElement = $get("ResultId");
  7. PageMethods.SetSessionValue("SessionValue", Date(),
  8. OnSucceeded, OnFailed);
  9. }
  10. // Gets the session state value.
  11. function GetSessionValue(key)
  12. {
  13. PageMethods.GetSessionValue(key,
  14. OnSucceeded, OnFailed);
  15. }
  16. //Sets the session state value.
  17. function SetSessionValue(key, value)
  18. {
  19. PageMethods.SetSessionValue(key, value,
  20. OnSucceeded, OnFailed);
  21. }
  22. // Callback function invoked on successful
  23. // completion of the page method.
  24. function OnSucceeded(result, userContext, methodName)
  25. {
  26. if (methodName == "GetSessionValue")
  27. {
  28. displayElement.innerHTML = "Current session state value: " +
  29. result;
  30. }
  31. }
  32. // Callback function invoked on failure
  33. // of the page method.
  34. function OnFailed(error, userContext, methodName)
  35. {
  36. if(error !== null)
  37. {
  38. displayElement.innerHTML = "An error occurred: " +
  39. error.get_message();
  40. }
  41. }
  42. if (typeof(Sys) !== "undefined") Sys.Application.notifyScriptLoaded();