1 using System;
2 using System.Collections.Generic;
3 using System.Text;
4
5 using System.Web.UI;
6 using System.Web.UI.WebControls;
7 using System.Web.UI.WebControls.WebParts;
8 using System.Web.UI.HtmlControls;
9
10 namespace Eallies.WebParts.Sample
11 {
12 public class Time : WebPart, INamingContainer
13 {
14 private string _Text;
15
16 private HtmlTableCell _HtmlTableCell = new HtmlTableCell();
17
18 private TextBox _TextBox = new TextBox();
19 private Button _Button = new Button();
20
21 public Time()
22 {
23 this._Button.Click += delegate(object sender, EventArgs e)
24 {
25 this._Text = DateTime.Now.ToString();
26
27 this._HtmlTableCell.InnerHtml = "";
28 this.AddControls();
29 };
30 }
31
32 [WebBrowsable(true), Personalizable(true)]
33 public string Text
34 {
35 get { return _Text; }
36 set { _Text = value; }
37 }
38
39 protected override void CreateChildControls()
40 {
41 this.Controls.Add(new LiteralControl("<table>" + "\n"));
42 this.Controls.Add(new LiteralControl(" <tr>" + "\n"));
43 this.Controls.Add(this._HtmlTableCell);
44 this.Controls.Add(new LiteralControl(" </tr>" + "\n"));
45 this.Controls.Add(new LiteralControl("</table>" + "\n"));
46
47 if (this.Page.IsPostBack == false) this.AddControls();
48 }
49
50 protected override void OnLoad(EventArgs e)
51 {
52 base.OnLoad(e);
53
54 if (this.Page.IsPostBack == true) this.AddControls();
55 }
56
57 protected override void Render(HtmlTextWriter writer)
58 {
59 base.Render(writer);
60 }
61
62 private void AddControls()
63 {
64 this._TextBox.ID = this.ID + "TextBox";
65 this._TextBox.Text = this._Text;
66 this._HtmlTableCell.Controls.Add(this._TextBox);
67
68 this._HtmlTableCell.Controls.Add(new LiteralControl("<br>"));
69
70 this._Button.ID = this.ID + "Button";
71 this._Button.Text = "Get Time";
72 this._HtmlTableCell.Controls.Add(this._Button);
73 }
74 }
75 }