温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:特瑞飞家教信息平台源码
当前文件:
HomeTeachingNet/Controls/SubmitTextbox.cs[3K,2009-6-12 11:44:15],打开代码结构图
HomeTeachingNet/Controls/SubmitTextbox.cs[3K,2009-6-12 11:44:15],打开代码结构图1using System; 2
using System.Data; 3
using System.Configuration; 4
using System.Web; 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
using System.ComponentModel; 10
using System.Collections; 11
12
namespace Controls 13
{ 14
/// <summary> 15
/// SubmitTextbox 的摘要说明 16
/// </summary> 17
public class SubmitTextbox : TextBox 18
{ 19
[TypeConverter(typeof(SubmitableControlConvertor)), DefaultValue(""), Category("Behavior")] 20
public string SubmitControl 21
{ 22
get 23
{ 24
object ret = this.ViewState["SubmitControl"]; 25
if (ret != null) 26
{ 27
return (string)ret; 28
} 29
return string.Empty; 30
} 31
set 32
{ 33
this.ViewState["SubmitControl"] = value; 34
} 35
} 36
37
protected override void AddAttributesToRender(HtmlTextWriter writer) 38
{ 39
base.AddAttributesToRender(writer); 40
if (this.SubmitControl.Length > 0) 41
{ 42
Control con = FindControl(SubmitControl); 43
if (con != null) 44
{ 45
string script = "if(event.keyCode == 13){document.getElementById('" + con.ClientID + "').click(); event.returnValue=false;}"; 46
writer.AddAttribute("onkeydown", script); 47
} 48
} 49
} 50
} 51
52
public class SubmitableControlConvertor : StringConverter 53
{ 54
private object[] GetControls(IContainer container) 55
{ 56
ComponentCollection components = container.Components; 57
ArrayList ret = new ArrayList(); 58
foreach (IComponent control in components) 59
{ 60
if (!(control is Button || control is LinkButton || control is ImageButton)) 61
{ 62
continue; 63
} 64
Control button = (Control)control; 65
if ((button.ID != null) && (button.ID.Length != 0)) 66
{ 67
ret.Add(string.Copy(button.ID)); 68
} 69
} 70
ret.Sort(Comparer.Default); 71
return ret.ToArray(); 72
} 73
74
75
public override System.ComponentModel.TypeConverter.StandardValuesCollection GetStandardValues(ITypeDescriptorContext context) 76
{ 77
if ((context != null) && (context.Container != null)) 78
{ 79
object[] controls = this.GetControls(context.Container); 80
if (controls != null) 81
{ 82
return new TypeConverter.StandardValuesCollection(controls); 83
} 84
} 85
return null; 86
} 87
88
public override bool GetStandardValuesExclusive(ITypeDescriptorContext context) 89
{ 90
return false; 91
} 92
93
public override bool GetStandardValuesSupported(ITypeDescriptorContext context) 94
{ 95
return true; 96
} 97
} 98
99
}






}