fork download
  1. #region Namespaces
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Web;
  6. using System.Web.UI;
  7. using System.Web.UI.WebControls;
  8. #endregion
  9.  
  10.  
  11. namespace ModuleCreateNewOffer
  12. {
  13. class Templates
  14. {
  15. internal class ButtonItem
  16. {
  17. private int width;
  18. private int height;
  19. private string caption;
  20.  
  21. // Properties
  22. internal int Width { get { return width; } set { width = value; } }
  23. internal int Height { get { return height; } set { height = value; } }
  24. internal string Caption { get { return caption; } set { caption = value; } }
  25.  
  26. internal ButtonItem(int inputWidth, int inputHeight, string captionText)
  27. {
  28. this.Width = inputWidth;
  29. this.Height = inputHeight;
  30. this.Caption = captionText;
  31. }
  32. }
  33. }
  34.  
  35. class EventController
  36. {
  37. internal static class Buttons
  38. {
  39. internal static void HandleButton(object sender, EventArgs e)
  40. {
  41. Button item = sender as Button;
  42. item.Text = "clicked!";
  43. }
  44. }
  45. }
  46.  
  47. public partial class Default : System.Web.UI.Page
  48. {
  49. enum UIElements
  50. {
  51. Button,
  52. };
  53.  
  54. Action<UIElements> createUIControl = null;
  55.  
  56. protected void Page_Load(object sender, EventArgs e) // MS developers, why don't you name the `Page_Load()` standard method just `PageCall()` ?
  57. {
  58. PageSetup();
  59. }
  60.  
  61. void PageSetup()
  62. {
  63. InitWizard();
  64. InitUpdatePanel();
  65. }
  66.  
  67. void InitWizard()
  68. {
  69. createUIControl = (item) => CreateNewUIControl(item);
  70. }
  71.  
  72. void InitUpdatePanel()
  73. {
  74. createUIControl(UIElements.Button);
  75. }
  76.  
  77. void CreateNewUIControl(UIElements controlType)
  78. {
  79. switch (controlType)
  80. {
  81. case UIElements.Button:
  82. this.UpdatePanel.ContentTemplateContainer.Controls.Add(CreateNewButton(new Templates.ButtonItem(100, 20, "click me")));
  83. break;
  84. }
  85. }
  86.  
  87. Button CreateNewButton(Templates.ButtonItem template)
  88. {
  89. Button item = new Button();
  90. item.ID = "button" + Guid.NewGuid().ToString();
  91. item.Click += new EventHandler(EventController.Buttons.HandleButton);
  92. item.Height = template.Height;
  93. item.Width = template.Width;
  94. item.Text = template.Caption;
  95. return item;
  96. }
  97. }
  98. }
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty