blob: ecd437a237e1109069ad6367c45d42e7d4507857 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
/* System.Web.UI.HtmlControls
* Authors
* Leen Toelen (toelen@hotmail.com)
*/
using System;
using System.ComponentModel;
using System.Globalization;
using System.Web;
using System.Web.UI;
namespace System.Web.UI.HtmlControls{
[DefaultEvent("ServerClick")]
public class HtmlInputButton : HtmlInputControl, IPostBackEventHandler{
private static readonly object EventServerClick = new object ();
public HtmlInputButton(): base ("button")
{
}
public HtmlInputButton(string type): base(type){}
protected override void OnPreRender (EventArgs e)
{
base.OnPreRender(e);
if (Page != null && Events [EventServerClick] != null)
Page.RequiresPostBackScript ();
}
protected override void RenderAttributes (HtmlTextWriter writer)
{
if (Page != null && CausesValidation) {
string type = Type;
if (String.Compare (type, "button", true) == 0 || String.Compare (type, "submit", true) == 0) {
string script = Page.GetPostBackClientEvent (this, String.Empty);
AttributeCollection coll = Attributes;
if (coll ["language"] != null)
coll.Remove ("language");
writer.WriteAttribute ("language", "javascript");
string onclick;
if ((onclick = coll ["onclick"]) != null) {
script = onclick + " " + script;
coll.Remove ("onclick");
}
writer.WriteAttribute ("onclick", script);
}
}
base.RenderAttributes (writer);
}
protected virtual void OnServerClick(EventArgs e){
EventHandler handler = (EventHandler) Events[EventServerClick];
if (handler != null){
handler (this, e);
}
}
void IPostBackEventHandler.RaisePostBackEvent (string eventArgument)
{
if(CausesValidation == true){
Page.Validate();
}
OnServerClick(EventArgs.Empty);
}
[WebCategory("Action")]
[WebSysDescription("Fires when the control is clicked.")]
public event EventHandler ServerClick{
add{
Events.AddHandler(EventServerClick, value);
}
remove{
Events.RemoveHandler(EventServerClick, value);
}
}
[DefaultValue(true)]
[WebCategory("Behavior")]
public bool CausesValidation{
get{
object causesVal = ViewState["CausesValidation"];
if (causesVal != null){
return (Boolean) causesVal;
}
return true;
}
set{
ViewState["CausesValidation"] = (Boolean) value;
}
}
} // end of System.Web.UI.HtmlControls.HtmlInputButton
} // namespace System.Web.UI.HtmlControls
|