okay so most of this code is still in an experimental stage, thus all the different random lines of code to try and test stuff out.
with that said, this is main class of the ASP.NET server control. the overall design is an AJAX UpdatePanel containing a textbox and a HoverMenuExtender attached to it. The functionality i want is to select one of the menu items of the HoverMenu and cause a postback for the UpdatePanel, once i can get that, i can add the code to handle what the UpdatePanel should load next.
My whole reason for using the UpdatePanel and the HoverMenuExtender was within the ASP.NET server control was to avoid doing AJAX/javascript coding myself.
The code below doesn't cause any postback when clicking on the items. the __doPostBack doesn't reference the UpdatePanel but the menuitems which doesn't have a postback, obviously.
1 [DefaultProperty("Text")]
2 [ToolboxData("<{0}:MagicText runat=server></{0}:MagicText>")]
3 public class MagicText : WebControl
4 {
5 protected UpdatePanel panel;
6 protected HoverMenuExtender menu;
7 private HttpSessionState Session;
8 protected TextBox textbox;
9 protected Panel currentMenu;
10
11
12 [Bindable(true)]
13 [Category("Appearance")]
14 [DefaultValue("")]
15 [Localizable(true)]
16 public string Text
17 {
18 get
19 {
20 String s = (String)ViewState["Text"];
21 return ((s == null) ? "[" + this.ID + "]" : s);
22 }
23
24 set
25 {
26 ViewState["Text"] = value;
27 }
28 }
29
30 protected override void CreateChildControls()
31 {
32 panel = new UpdatePanel();
33 this.Controls.Add(panel);
34 panel.ID = this.ID + "ajaxPanel";
35
36 panel.UpdateMode = UpdatePanelUpdateMode.Conditional;
37 panel.ChildrenAsTriggers = true;
38 panel.Load += new EventHandler(UpdatePanel_OnLoad);
39 textbox = new TextBox();
40 textbox.ReadOnly = true;
41 textbox.ID = this.ID + "textbox";
42 textbox.Text = Text;
43 Button b = new Button();
44 b.CommandName = "hi";
45 b.Text = "hi";
46 b.Click += new EventHandler(ButtonClick);
47 b.ID = "button1";
48 panel.ContentTemplateContainer.Controls.Add(b);
49 menu = new HoverMenuExtender();
50 menu.ID = this.ID + "AjaxHoverMenu";
51 menu.BehaviorID = this.ID + "AjaxHoverMenuBehavior";
52 menu.PopupControlID = GetPanelForMenu();
53 menu.TargetControlID = textbox.ID;
54 menu.HoverCssClass = "popupHover";
55 menu.HoverDelay = 25;
56 menu.PopupPosition = HoverMenuPopupPosition.Right;
57 panel.ContentTemplateContainer.Controls.Add(textbox);
58 panel.ContentTemplateContainer.Controls.Add(menu);
59 panel.ContentTemplateContainer.Controls.Add(currentMenu);
60
61 PostBackTrigger trigger = new PostBackTrigger();
62 trigger.ControlID = b.ClientID.ToString();
63 panel.Triggers.Add(trigger);
64
65 base.CreateChildControls();
66 //panel.Controls.Add(currentMenu);
67
68 }
69
70 void ButtonClick(object sender, EventArgs e)
71 {
72 }
73
74 protected string GetPanelForMenu()
75 {
76 currentMenu = new Panel();
77 currentMenu.ID = this.ID + "menuForPopup";
78 currentMenu.CssClass = "popupMenu";
79 LinkButton lb;
80
81 lb = new LinkButton();
82 lb.ID = "magicMenuItem1";
83 lb.CssClass = "popupItem";
84 lb.Click += new EventHandler(ModifyText);
85 lb.Text = "Edit";
86 currentMenu.Controls.Add(lb);
87
88
89 currentMenu.Controls.Add(new LiteralControl("<br/>"));
90
91 lb = new LinkButton();
92 lb.ID = "magicMenuItem2";
93 lb.CssClass = "popupItem";
94 lb.Text = "Add";
95 //lb.Click += new EventHandler(AddToText);
96 lb.CommandName = "Add";
97 currentMenu.Controls.Add(lb);
98
99 currentMenu.Controls.Add(new LiteralControl("<br/>"));
100
101 lb = new LinkButton();
102 lb.ID = "magicMenuItem3";
103 lb.CssClass = "popupItem";
104 lb.Click += new EventHandler(TranslateText);
105 lb.Text = "Translate";
106 currentMenu.Controls.Add(lb);
107
108 currentMenu.Controls.Add(new LiteralControl("<br/>"));
109
110 lb = new LinkButton();
111 lb.ID = "magicMenuItem4";
112 lb.CssClass = "popupItem";
113 lb.Click += new EventHandler(CommentText);
114 lb.Text = "Comment";
115 currentMenu.Controls.Add(lb);
116
117 currentMenu.Controls.Add(new LiteralControl("<br/>"));
118
119 lb = new LinkButton();
120 lb.ID = "magicMenuItem5";
121 lb.CssClass = "popupItem";
122 lb.Click += new EventHandler(FlagText);
123 lb.Text = "Flag";
124 currentMenu.Controls.Add(lb);
125
126 currentMenu.Controls.Add(new LiteralControl("<br/>"));
127
128 lb = new LinkButton();
129 lb.ID = "magicMenuItem6";
130 lb.CssClass = "popupItem";
131 lb.Click += new EventHandler(ViewRevisionHistory);
132 lb.Text = "View Revisions";
133 currentMenu.Controls.Add(lb);
134
135 currentMenu.Controls.Add(new LiteralControl("<br/>"));
136
137 return currentMenu.ID;
138 }
139
140 void UpdatePanel_OnLoad(object sender, EventArgs e)
141 {
142 int x = 0;
143 x = x;
144 }
145
146 void ModifyText(object sender, EventArgs e)
147 {
148 textbox.ReadOnly = false;
149 textbox.BackColor = Color.Pink;
150 }
151
152 void AddToText(object sender, EventArgs e)
153 {
154 throw new NotImplementedException();
155 }
156
157 void TranslateText(object sender, EventArgs e)
158 {
159 throw new NotImplementedException();
160 }
161
162 void CommentText(object sender, EventArgs e)
163 {
164 throw new NotImplementedException();
165 }
166
167 void FlagText(object sender, EventArgs e)
168 {
169 throw new NotImplementedException();
170 }
171
172 void ViewRevisionHistory(object sender, EventArgs e)
173 {
174 throw new NotImplementedException();
175 }
176
177
178 protected override void RenderContents(HtmlTextWriter output)
179 {
180 panel.RenderControl(output);
181 currentMenu.RenderControl(output);
182 }
183
184 void RenderMenu(HtmlTextWriter writer)
185 {
186 base.Render(writer);
187 }
188 }