customcontrol.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. using System;
  2. using System.Drawing;
  3. using System.Web.UI;
  4. using System.Web;
  5. using System.Globalization;
  6. namespace SampleControl
  7. {
  8. public class UpdatePanelAnimationWithClientResource : Control
  9. {
  10. private string _updatePanelID;
  11. private Color _borderColor;
  12. private Boolean _animate;
  13. public Color BorderColor
  14. {
  15. get
  16. {
  17. return _borderColor;
  18. }
  19. set
  20. {
  21. _borderColor = value;
  22. }
  23. }
  24. public string UpdatePanelID
  25. {
  26. get
  27. {
  28. return _updatePanelID;
  29. }
  30. set
  31. {
  32. _updatePanelID = value;
  33. }
  34. }
  35. public Boolean Animate
  36. {
  37. get
  38. {
  39. return _animate;
  40. }
  41. set
  42. {
  43. _animate = value;
  44. }
  45. }
  46. protected override void OnPreRender(EventArgs e)
  47. {
  48. base.OnPreRender(e);
  49. if (Animate)
  50. {
  51. UpdatePanel updatePanel = (UpdatePanel)FindControl(UpdatePanelID);
  52. string script = String.Format(
  53. CultureInfo.InvariantCulture,
  54. @"
  55. Sys.Application.add_load(function(sender, args) {{
  56. var {0}_borderAnimation = new BorderAnimation('{1}');
  57. var panelElement = document.getElementById('{0}');
  58. if (args.get_isPartialLoad()) {{
  59. {0}_borderAnimation.animate(panelElement);
  60. }}
  61. }})
  62. ",
  63. updatePanel.ClientID,
  64. ColorTranslator.ToHtml(BorderColor));
  65. ScriptManager.RegisterStartupScript(
  66. this,
  67. typeof(UpdatePanelAnimationWithClientResource),
  68. ClientID,
  69. script,
  70. true);
  71. }
  72. }
  73. }
  74. }