#region Namespaces
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
#endregion
namespace ModuleCreateNewOffer
{
class Templates
{
internal class ButtonItem
{
private int width;
private int height;
private string caption;
// Properties
internal int Width { get { return width; } set { width = value; } }
internal int Height { get { return height; } set { height = value; } }
internal string Caption { get { return caption; } set { caption = value; } }
internal ButtonItem(int inputWidth, int inputHeight, string captionText)
{
this.Width = inputWidth;
this.Height = inputHeight;
this.Caption = captionText;
}
}
}
class EventController
{
internal static class Buttons
{
internal static void HandleButton(object sender, EventArgs e)
{
Button item = sender as Button;
item.Text = "clicked!";
}
}
}
public partial class Default : System.Web.UI.Page
{
enum UIElements
{
Button,
};
Action<UIElements> createUIControl = null;
protected void Page_Load(object sender, EventArgs e) // MS developers, why don't you name the `Page_Load()` standard method just `PageCall()` ?
{
PageSetup();
}
void PageSetup()
{
InitWizard();
InitUpdatePanel();
}
void InitWizard()
{
createUIControl = (item) => CreateNewUIControl(item);
}
void InitUpdatePanel()
{
createUIControl(UIElements.Button);
}
void CreateNewUIControl(UIElements controlType)
{
switch (controlType)
{
case UIElements.Button:
this.UpdatePanel.ContentTemplateContainer.Controls.Add(CreateNewButton(new Templates.ButtonItem(100, 20, "click me")));
break;
}
}
Button CreateNewButton(Templates.ButtonItem template)
{
Button item = new Button();
item.ID = "button" + Guid.NewGuid().ToString();
item.Click += new EventHandler(EventController.Buttons.HandleButton);
item.Height = template.Height;
item.Width = template.Width;
item.Text = template.Caption;
return item;
}
}
}