using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using System.ComponentModel;
using System.Web.UI.HtmlControls;
using System.Web;
using System.Web.UI.WebControls;
using System.Collections;
[assembly: WebResource("Framework.Library.Web.WebControl.jquery.ui.autobox.css", "text/css", PerformSubstitution=true)]
[assembly: WebResource("Framework.Library.Web.WebControl.close.gif", "image/gif")]
[assembly: WebResource("Framework.Library.Web.WebControl.jquery.min.js", "application/x-javascript")]
[assembly: WebResource("Framework.Library.Web.WebControl.jquery.contextmenu.r2.js", "application/x-javascript")]
[assembly: WebResource("Framework.Library.Web.WebControl.jquery.templating.js", "application/x-javascript")]
[assembly: WebResource("Framework.Library.Web.WebControl.jquery.ui.autobox.js", "application/x-javascript")]
[assembly: WebResource("Framework.Library.Web.WebControl.jquery.ui.autobox.ext.js", "application/x-javascript")]
namespace Framework.Library.Web.WebControl
{
public class EmailAutoComplete : Control
{
[Category("Behavior")]
[Description("璇锋眰鑾峰彇鏁版嵁鐨刄rl銆?)]
[DefaultValue("")]
public string AjaxUrl
{
get
{
object o = ViewState["AjaxUrl"];
if (o == null)
return "";
return o.ToString();
}
set { ViewState["AjaxUrl"] = value; }
}
//[Category("Behavior")]
//[Description("瑕佸啓鍏ユ帶浠跺璞$殑ClientID銆?)]
//[DefaultValue("")]
//public string TagObjectId
//{
// get
// {
// object o = ViewState["TagObjectId"];
// if (o == null)
// return this.ID + "_TagObjectId";
// return o.ToString();
// }
// set { ViewState["TagObjectId"] = value; }
//}
[Category("Behavior")]
[Description("楠岃瘉鍖归厤鍓嶇JS鏂规硶銆?)]
[DefaultValue("function(typed) { return this.text.match(new RegExp(typed, 'i')); }")]
public string Match
{
get
{
object o = ViewState["Match"];
if (o == null)
return "function(typed) { return this.text.match(new RegExp(typed, 'i')); }";
return o.ToString();
}
set { ViewState["Match"] = value; }
}
[Category("Behavior")]
[Description("鍐欏叆鑾峰彇鏁版嵁鐨勫墠绔鐞咼S鏂规硶銆?)]
[DefaultValue("function(obj) { return obj.text }")]
public string InsertText
{
get
{
object o = ViewState["InsertText"];
if (o == null)
return "function(obj) { return obj.text }";
return o.ToString();
}
set { ViewState["InsertText"] = value; }
}
[Category("Behavior")]
[Description("鍒楄〃椤规ā鍧椼€?)]
[DefaultValue("<li><#= text #></li>")]
public string TemplateText
{
get
{
object o = ViewState["TemplateText"];
if (o == null)
return "<li><#= text #></li>";
return o.ToString();
}
set { ViewState["TemplateText"] = value; }
}
[Category("Behavior")]
[Description("闄勫姞鍙戦€佸弬鏁般€?)]
[DefaultValue("")]
public string PostParams
{
get
{
object o = ViewState["PostParams"];
if (o == null)
return "";
return o.ToString();
}
set { ViewState["PostParams"] = value; }
}
[Category("Behavior")]
[Description("鏌ヨ鍏抽敭璇嶅弬鏁般€?)]
[DefaultValue("searchKey")]
public string KeyParams
{
get
{
object o = ViewState["KeyParams"];
if (o == null)
return "searchKey";
return o.ToString();
}
set { ViewState["KeyParams"] = value; }
}
[Category("Behavior")]
[Description("鍒濆鍙傛暟銆?)]
[DefaultValue("")]
public string Text
{
get
{
object o = ViewState["Text"];
if (o == null)
return "";
return o.ToString();
}
set { ViewState["Text"] = value; }
}
[Category("Behavior")]
[Description("璁剧疆鎴栬鍙?鍙銆?)]
[DefaultValue(false)]
public bool ReadOnly
{
get
{
object o = ViewState["ReadOnly"];
if (o == null)
return false;
return Convert.ToBoolean(o);
}
set
{
ViewState["ReadOnly"] = value;
}
}
public string[] EmailAddress
{
get
{
try
{
string tmps = Page.Request[this.ClientID];
System.Text.RegularExpressions.Regex reg = new System.Text.RegularExpressions.Regex(@"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*");
ArrayList results = new ArrayList();
if (!string.IsNullOrEmpty(tmps))
{
foreach (string i in tmps.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries))
{
if (reg.IsMatch(i))
results.Add(i);
}
}
else
{
return new string[0];
}
return Array.ConvertAll<object, string>(results.ToArray(), delegate(object i) { return i.ToString(); });
}
catch
{
return new string[0];
}
}
}
public string[] EmailNames
{
get
{
try
{
string tmps = Page.Request[this.ClientID];
System.Text.RegularExpressions.Regex reg = new System.Text.RegularExpressions.Regex(@"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*");
ArrayList results = new ArrayList();
if (!string.IsNullOrEmpty(tmps))
{
foreach (string i in tmps.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries))
{
if (!reg.IsMatch(i))
results.Add(i);
}
}
else
{
return new string[0];
}
return Array.ConvertAll<object, string>(results.ToArray(), delegate(object i) { return i.ToString(); });
}
catch
{
return new string[0];
}
}
}
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
HtmlLink cssLink = new HtmlLink();
cssLink.Href = Page.ClientScript.GetWebResourceUrl(this.GetType(), "Framework.Library.Web.WebControl.jquery.ui.autobox.css");
cssLink.Attributes.Add("rel", "stylesheet");
cssLink.Attributes.Add("type", "text/css");
Page.Header.Controls.Add(cssLink);
HtmlGenericControl Include1 = new HtmlGenericControl("script");
Include1.Attributes.Add("type", "text/javascript");
Include1.Attributes.Add("src", Page.ClientScript.GetWebResourceUrl(this.GetType(), "Framework.Library.Web.WebControl.jquery.min.js"));
Page.Header.Controls.Add(Include1);
HtmlGenericControl Include5 = new HtmlGenericControl("script");
Include5.Attributes.Add("type", "text/javascript");
Include5.Attributes.Add("src", Page.ClientScript.GetWebResourceUrl(this.GetType(), "Framework.Library.Web.WebControl.jquery.contextmenu.r2.js"));
Page.Header.Controls.Add(Include5);
HtmlGenericControl Include4 = new HtmlGenericControl("script");
Include4.Attributes.Add("type", "text/javascript");
Include4.Attributes.Add("src", Page.ClientScript.GetWebResourceUrl(this.GetType(), "Framework.Library.Web.WebControl.jquery.templating.js"));
Page.Header.Controls.Add(Include4);
HtmlGenericControl Include2 = new HtmlGenericControl("script");
Include2.Attributes.Add("type", "text/javascript");
Include2.Attributes.Add("src", Page.ClientScript.GetWebResourceUrl(this.GetType(), "Framework.Library.Web.WebControl.jquery.ui.autobox.js"));
Page.Header.Controls.Add(Include2);
HtmlGenericControl Include3 = new HtmlGenericControl("script");
Include3.Attributes.Add("type", "text/javascript");
Include3.Attributes.Add("src", Page.ClientScript.GetWebResourceUrl(this.GetType(), "Framework.Library.Web.WebControl.jquery.ui.autobox.ext.js"));
Page.Header.Controls.Add(Include3);
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
System.Text.StringBuilder sb = new StringBuilder();
foreach(string mt in this.Text.Split(";".ToCharArray(), StringSplitOptions.RemoveEmptyEntries))
{
sb.AppendFormat("{0}autobox[0].addBox('{1}');", this.ClientID, mt);
}
string initScript = @" $(function() {{var {0}autobox = $('input.{0}').autobox({{
ajax: '{1}',
//valueObj: '{2}',
match: {3},
insertText: {4},
templateText: '{5}',
postParams:'{6}',
keyName:'{7}',
readyOnly: {8}
}});if ($('#{2}')) $('#{2}').val(''); {9} }});";
initScript = string.Format(initScript, this.ClientID,
this.AjaxUrl,
"",//this.TagObjectId,
this.Match,
this.InsertText,
this.TemplateText,
this.PostParams,
this.KeyParams,
(this.ReadOnly?"true":"false"),
sb.ToString()
);
Page.ClientScript.RegisterStartupScript(this.GetType(), this.ClientID, initScript, true);
Page.ClientScript.RegisterStartupScript(this.GetType(), "_contentMenu_", "<div class='contextMenu' id='emailautocomplete_contentMenu'><ul><li id='open'>灞曞紑</li></ul></div>", false);
//Page.RegisterHiddenField(this.TagObjectId, "");
}
protected override void Render(HtmlTextWriter writer)
{
base.Render(writer);
string html =@"<input type='hidden' name='{0}' id='{0}' class='{0}' />";
html = string.Format(html, this.ClientID);
writer.Write(html);
}
}
}
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using System.ComponentModel;
using System.Web.UI.HtmlControls;
using System.Web;
using System.Web.UI.WebControls;
using System.Collections;
[assembly: WebResource("Framework.Library.Web.WebControl.jquery.ui.autobox.css", "text/css", PerformSubstitution=true)]
[assembly: WebResource("Framework.Library.Web.WebControl.close.gif", "image/gif")]
[assembly: WebResource("Framework.Library.Web.WebControl.jquery.min.js", "application/x-javascript")]
[assembly: WebResource("Framework.Library.Web.WebControl.jquery.contextmenu.r2.js", "application/x-javascript")]
[assembly: WebResource("Framework.Library.Web.WebControl.jquery.templating.js", "application/x-javascript")]
[assembly: WebResource("Framework.Library.Web.WebControl.jquery.ui.autobox.js", "application/x-javascript")]
[assembly: WebResource("Framework.Library.Web.WebControl.jquery.ui.autobox.ext.js", "application/x-javascript")]
namespace Framework.Library.Web.WebControl
{
public class EmailAutoComplete : Control
{
[Category("Behavior")]
[Description("璇锋眰鑾峰彇鏁版嵁鐨刄rl銆?)]
[DefaultValue("")]
public string AjaxUrl
{
get
{
object o = ViewState["AjaxUrl"];
if (o == null)
return "";
return o.ToString();
}
set { ViewState["AjaxUrl"] = value; }
}
//[Category("Behavior")]
//[Description("瑕佸啓鍏ユ帶浠跺璞$殑ClientID銆?)]
//[DefaultValue("")]
//public string TagObjectId
//{
// get
// {
// object o = ViewState["TagObjectId"];
// if (o == null)
// return this.ID + "_TagObjectId";
// return o.ToString();
// }
// set { ViewState["TagObjectId"] = value; }
//}
[Category("Behavior")]
[Description("楠岃瘉鍖归厤鍓嶇JS鏂规硶銆?)]
[DefaultValue("function(typed) { return this.text.match(new RegExp(typed, 'i')); }")]
public string Match
{
get
{
object o = ViewState["Match"];
if (o == null)
return "function(typed) { return this.text.match(new RegExp(typed, 'i')); }";
return o.ToString();
}
set { ViewState["Match"] = value; }
}
[Category("Behavior")]
[Description("鍐欏叆鑾峰彇鏁版嵁鐨勫墠绔鐞咼S鏂规硶銆?)]
[DefaultValue("function(obj) { return obj.text }")]
public string InsertText
{
get
{
object o = ViewState["InsertText"];
if (o == null)
return "function(obj) { return obj.text }";
return o.ToString();
}
set { ViewState["InsertText"] = value; }
}
[Category("Behavior")]
[Description("鍒楄〃椤规ā鍧椼€?)]
[DefaultValue("<li><#= text #></li>")]
public string TemplateText
{
get
{
object o = ViewState["TemplateText"];
if (o == null)
return "<li><#= text #></li>";
return o.ToString();
}
set { ViewState["TemplateText"] = value; }
}
[Category("Behavior")]
[Description("闄勫姞鍙戦€佸弬鏁般€?)]
[DefaultValue("")]
public string PostParams
{
get
{
object o = ViewState["PostParams"];
if (o == null)
return "";
return o.ToString();
}
set { ViewState["PostParams"] = value; }
}
[Category("Behavior")]
[Description("鏌ヨ鍏抽敭璇嶅弬鏁般€?)]
[DefaultValue("searchKey")]
public string KeyParams
{
get
{
object o = ViewState["KeyParams"];
if (o == null)
return "searchKey";
return o.ToString();
}
set { ViewState["KeyParams"] = value; }
}
[Category("Behavior")]
[Description("鍒濆鍙傛暟銆?)]
[DefaultValue("")]
public string Text
{
get
{
object o = ViewState["Text"];
if (o == null)
return "";
return o.ToString();
}
set { ViewState["Text"] = value; }
}
[Category("Behavior")]
[Description("璁剧疆鎴栬鍙?鍙銆?)]
[DefaultValue(false)]
public bool ReadOnly
{
get
{
object o = ViewState["ReadOnly"];
if (o == null)
return false;
return Convert.ToBoolean(o);
}
set
{
ViewState["ReadOnly"] = value;
}
}
public string[] EmailAddress
{
get
{
try
{
string tmps = Page.Request[this.ClientID];
System.Text.RegularExpressions.Regex reg = new System.Text.RegularExpressions.Regex(@"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*");
ArrayList results = new ArrayList();
if (!string.IsNullOrEmpty(tmps))
{
foreach (string i in tmps.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries))
{
if (reg.IsMatch(i))
results.Add(i);
}
}
else
{
return new string[0];
}
return Array.ConvertAll<object, string>(results.ToArray(), delegate(object i) { return i.ToString(); });
}
catch
{
return new string[0];
}
}
}
public string[] EmailNames
{
get
{
try
{
string tmps = Page.Request[this.ClientID];
System.Text.RegularExpressions.Regex reg = new System.Text.RegularExpressions.Regex(@"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*");
ArrayList results = new ArrayList();
if (!string.IsNullOrEmpty(tmps))
{
foreach (string i in tmps.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries))
{
if (!reg.IsMatch(i))
results.Add(i);
}
}
else
{
return new string[0];
}
return Array.ConvertAll<object, string>(results.ToArray(), delegate(object i) { return i.ToString(); });
}
catch
{
return new string[0];
}
}
}
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
HtmlLink cssLink = new HtmlLink();
cssLink.Href = Page.ClientScript.GetWebResourceUrl(this.GetType(), "Framework.Library.Web.WebControl.jquery.ui.autobox.css");
cssLink.Attributes.Add("rel", "stylesheet");
cssLink.Attributes.Add("type", "text/css");
Page.Header.Controls.Add(cssLink);
HtmlGenericControl Include1 = new HtmlGenericControl("script");
Include1.Attributes.Add("type", "text/javascript");
Include1.Attributes.Add("src", Page.ClientScript.GetWebResourceUrl(this.GetType(), "Framework.Library.Web.WebControl.jquery.min.js"));
Page.Header.Controls.Add(Include1);
HtmlGenericControl Include5 = new HtmlGenericControl("script");
Include5.Attributes.Add("type", "text/javascript");
Include5.Attributes.Add("src", Page.ClientScript.GetWebResourceUrl(this.GetType(), "Framework.Library.Web.WebControl.jquery.contextmenu.r2.js"));
Page.Header.Controls.Add(Include5);
HtmlGenericControl Include4 = new HtmlGenericControl("script");
Include4.Attributes.Add("type", "text/javascript");
Include4.Attributes.Add("src", Page.ClientScript.GetWebResourceUrl(this.GetType(), "Framework.Library.Web.WebControl.jquery.templating.js"));
Page.Header.Controls.Add(Include4);
HtmlGenericControl Include2 = new HtmlGenericControl("script");
Include2.Attributes.Add("type", "text/javascript");
Include2.Attributes.Add("src", Page.ClientScript.GetWebResourceUrl(this.GetType(), "Framework.Library.Web.WebControl.jquery.ui.autobox.js"));
Page.Header.Controls.Add(Include2);
HtmlGenericControl Include3 = new HtmlGenericControl("script");
Include3.Attributes.Add("type", "text/javascript");
Include3.Attributes.Add("src", Page.ClientScript.GetWebResourceUrl(this.GetType(), "Framework.Library.Web.WebControl.jquery.ui.autobox.ext.js"));
Page.Header.Controls.Add(Include3);
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
System.Text.StringBuilder sb = new StringBuilder();
foreach(string mt in this.Text.Split(";".ToCharArray(), StringSplitOptions.RemoveEmptyEntries))
{
sb.AppendFormat("{0}autobox[0].addBox('{1}');", this.ClientID, mt);
}
string initScript = @" $(function() {{var {0}autobox = $('input.{0}').autobox({{
ajax: '{1}',
//valueObj: '{2}',
match: {3},
insertText: {4},
templateText: '{5}',
postParams:'{6}',
keyName:'{7}',
readyOnly: {8}
}});if ($('#{2}')) $('#{2}').val(''); {9} }});";
initScript = string.Format(initScript, this.ClientID,
this.AjaxUrl,
"",//this.TagObjectId,
this.Match,
this.InsertText,
this.TemplateText,
this.PostParams,
this.KeyParams,
(this.ReadOnly?"true":"false"),
sb.ToString()
);
Page.ClientScript.RegisterStartupScript(this.GetType(), this.ClientID, initScript, true);
Page.ClientScript.RegisterStartupScript(this.GetType(), "_contentMenu_", "<div class='contextMenu' id='emailautocomplete_contentMenu'><ul><li id='open'>灞曞紑</li></ul></div>", false);
//Page.RegisterHiddenField(this.TagObjectId, "");
}
protected override void Render(HtmlTextWriter writer)
{
base.Render(writer);
string html =@"<input type='hidden' name='{0}' id='{0}' class='{0}' />";
html = string.Format(html, this.ClientID);
writer.Write(html);
}
}
}
下载: