Discuz重写的TextBox控件

Discuz重写的TextBox控件,非常好用,就是看不懂,有高手能看懂的,给解释下!
ContractedBlock.gifExpandedBlockStart.gif
None.gifusing System;
None.gif
using System.Collections;
None.gif
using System.Web.UI;
None.gif
using System.Web.UI.WebControls;
None.gif
using System.Web.UI.HtmlControls;
None.gif
using System.ComponentModel;
None.gif
None.gif
namespace Discuz.Admin.Controls
ExpandedBlockStart.gifContractedBlock.gif
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//// <summary>
InBlock.gif    
/// TextBox 控件
ExpandedSubBlockEnd.gif    
/// </summary>

InBlock.gif    [DefaultProperty("Text"),ToolboxData("<{0}:TextBox runat=server></{0}:TextBox>")]
InBlock.gif    
public class TextBox : System.Web.UI.WebControls.WebControl,IPostBackDataHandler
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
protected System.Web.UI.WebControls.TextBox tb=new System.Web.UI.WebControls.TextBox();
InBlock.gif        
protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator1=new RequiredFieldValidator();
InBlock.gif        
protected System.Web.UI.WebControls.RegularExpressionValidator RegularExpressionValidator1=new RegularExpressionValidator();
InBlock.gif        
protected System.Web.UI.WebControls.RangeValidator rangevalidator=new System.Web.UI.WebControls.RangeValidator();
InBlock.gif
InBlock.gif        
public TextBox(): base()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{  
InBlock.gif            tb.Attributes.Add(
"onfocus","this.className='colorfocus';"); 
InBlock.gif            tb.Attributes.Add(
"onblur","this.className='colorblur';"); 
InBlock.gif            
InBlock.gif            tb.CssClass
="colorblur";
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
public void AddAttributes(string key ,string valuestr)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            tb.Attributes.Add(key,valuestr);
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
InBlock.gif        
//在属性RequiredFieldType后进行调用
InBlock.gif
        public void  SetValiateControls()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
this.Controls.Add(tb);
InBlock.gif        
InBlock.gif            
if((RequiredFieldType!=null)&&(RequiredFieldType!="")&&(RequiredFieldType!="暂无校验"))
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                RegularExpressionValidator1.Display
=System.Web.UI.WebControls.ValidatorDisplay.Dynamic;
InBlock.gif                RegularExpressionValidator1.ControlToValidate
=tb.ID;
InBlock.gif                RegularExpressionValidator1.ForeColor 
= System.Drawing.Color.Black;
InBlock.gif
InBlock.gif                
InBlock.gif                
switch (RequiredFieldType)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
case "数据校验":
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        RegularExpressionValidator1.ValidationExpression
=(this.ValidationExpression!=null)?this.ValidationExpression:"^[-]?\\d+[.]?\\d*$";
InBlock.gif                        RegularExpressionValidator1.ErrorMessage
=" 数字的格式不正确";break
ExpandedSubBlockEnd.gif                    }

InBlock.gif                    
case "电子邮箱":
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{   //RegularExpressionValidator1.ValidationExpression="^\\w+((-\\w+)|(\\.\\w+))*\\@[A-Za-z0-9]+((\\.|-)[A-Za-z0-9]+)*\\.[A-Za-z0-9]+$";
InBlock.gif
                        RegularExpressionValidator1.ValidationExpression=(this.ValidationExpression!=null)?this.ValidationExpression:(@"^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$");
InBlock.gif                        RegularExpressionValidator1.ErrorMessage
=" 邮箱的格式不正确";break
ExpandedSubBlockEnd.gif                    }

InBlock.gif                    
case "移动手机":
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        RegularExpressionValidator1.ValidationExpression
=(this.ValidationExpression!=null)?this.ValidationExpression:"\\d{11}";
InBlock.gif                        RegularExpressionValidator1.ErrorMessage
=" 手机的位数应为11位!";break
ExpandedSubBlockEnd.gif                    }

InBlock.gif                    
case "家用电话":
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        RegularExpressionValidator1.ValidationExpression
=(this.ValidationExpression!=null)?this.ValidationExpression:"((\\(\\d{3}\\) ?)|(\\d{3}-))?\\d{3}-\\d{4}|((\\(\\d{3}\\) ?)|(\\d{4}-))?\\d{4}-\\d{4}";
InBlock.gif                        RegularExpressionValidator1.ErrorMessage
=" 请依 (XXX)XXX-XXXX 格式或 (XXX)XXXX-XXXX 输入电话号码!";break
ExpandedSubBlockEnd.gif                    }

InBlock.gif                    
case "身份证号码":
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        RegularExpressionValidator1.ValidationExpression
=(this.ValidationExpression!=null)?this.ValidationExpression:"^\\d{15}$|^\\d{18}$";
InBlock.gif                        RegularExpressionValidator1.ErrorMessage
=" 请依15或18位数据的身份证号!";break
ExpandedSubBlockEnd.gif                    }

InBlock.gif                    
case "网页地址":
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        RegularExpressionValidator1.ValidationExpression
=(this.ValidationExpression!=null)?this.ValidationExpression:@"^(http|https)\://([a-zA-Z0-9\.\-]+(\:[a-zA-Z0-9\.&%\$\-]+)*@)*((25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])|localhost|([a-zA-Z0-9\-]+\.)*[a-zA-Z0-9\-]+\.(com|edu|gov|int|mil|net|org|biz|arpa|info|name|pro|aero|coop|museum|[a-zA-Z]{1,10}))(\:[0-9]+)*(/($|[a-zA-Z0-9\.\,\?\'\\\+&%\$#\=~_\-]+))*$";
InBlock.gif                        RegularExpressionValidator1.ErrorMessage
=" 请输入正确的网址";break
InBlock.gif
ExpandedSubBlockEnd.gif                    }

InBlock.gif                    
case "日期":
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{   //RegularExpressionValidator1.ValidationExpression="\\d{4}-\\d{1,2}-\\d{1,2}";
InBlock.gif
                        RegularExpressionValidator1.ValidationExpression=(this.ValidationExpression!=null)?this.ValidationExpression:@"^((((1[6-9]|[2-9]\d)\d{2})-(0?[13578]|1[02])-(0?[1-9]|[12]\d|3[01]))|(((1[6-9]|[2-9]\d)\d{2})-(0?[13456789]|1[012])-(0?[1-9]|[12]\d|30))|(((1[6-9]|[2-9]\d)\d{2})-0?2-(0?[1-9]|1\d|2[0-8]))|(((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))-0?2-29-))$"
InBlock.gif                        RegularExpressionValidator1.ErrorMessage
=" 请输入正确的日期,如:2006-1-1";break
ExpandedSubBlockEnd.gif                    }

InBlock.gif                    
case "日期时间":
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        RegularExpressionValidator1.ValidationExpression
=(this.ValidationExpression!=null)?this.ValidationExpression:@"^((((1[6-9]|[2-9]\d)\d{2})-(0?[13578]|1[02])-(0?[1-9]|[12]\d|3[01]))|(((1[6-9]|[2-9]\d)\d{2})-(0?[13456789]|1[012])-(0?[1-9]|[12]\d|30))|(((1[6-9]|[2-9]\d)\d{2})-0?2-(0?[1-9]|1\d|2[0-8]))|(((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))-0?2-29-)) (20|21|22|23|[0-1]?\d):[0-5]?\d:[0-5]?\d$"
InBlock.gif                        RegularExpressionValidator1.ErrorMessage
=" 请输入正确的日期,如: 2006-1-1 23:59:59";break
ExpandedSubBlockEnd.gif                    }

InBlock.gif                    
case "金额":
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        RegularExpressionValidator1.ValidationExpression
=(this.ValidationExpression!=null)?this.ValidationExpression:"^([0-9]|[0-9].[0-9]{0-2}|[1-9][0-9]*.[0-9]{0,2})$";
InBlock.gif                        RegularExpressionValidator1.ErrorMessage
=" 请输入正确的金额";break
ExpandedSubBlockEnd.gif                    }

InBlock.gif                    
case "IP地址":
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        RegularExpressionValidator1.ValidationExpression
=(this.ValidationExpression!=null)?this.ValidationExpression:@"^(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])$";
InBlock.gif                        RegularExpressionValidator1.ErrorMessage
=" 请输入正确的IP地址";break
ExpandedSubBlockEnd.gif                    }

InBlock.gif                    
case "IP地址带端口":
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        RegularExpressionValidator1.ValidationExpression
=(this.ValidationExpression!=null)?this.ValidationExpression:@"^(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9]):\d{1,5}?$";
InBlock.gif                        RegularExpressionValidator1.ErrorMessage
=" 请输入正确的带端口的IP地址";break
ExpandedSubBlockEnd.gif                    }

ExpandedSubBlockEnd.gif                }

InBlock.gif                
this.Controls.Add(RegularExpressionValidator1);
ExpandedSubBlockEnd.gif            }

InBlock.gif
InBlock.gif            
switch (CanBeNull)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif                
case "可为空":    dot.gif{    break;     }
InBlock.gif                
case "必填":
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    RequiredFieldValidator1.Display
=System.Web.UI.WebControls.ValidatorDisplay.Dynamic;
InBlock.gif                    RequiredFieldValidator1.ControlToValidate
=tb.ID;
InBlock.gif                    RequiredFieldValidator1.ForeColor
=System.Drawing.Color.Black;
InBlock.gif                    RequiredFieldValidator1.ErrorMessage
="请务必输入内容!";
InBlock.gif                    
this.Controls.Add(RequiredFieldValidator1);
InBlock.gif                    
break
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockStart.gifContractedSubBlock.gif                
default :    dot.gif{    break;     }
ExpandedSubBlockEnd.gif            }

InBlock.gif        
InBlock.gif            
InBlock.gif            
this.BorderStyle=BorderStyle.Dotted; 
InBlock.gif            
this.BorderWidth=1
InBlock.gif            
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        [Bindable(
true),Category("Appearance"),DefaultValue("")] 
InBlock.gif        
public string SetFocusButtonID
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
object o = ViewState[this.ClientID+"_SetFocusButtonID"];
InBlock.gif                
return (o==null)?"":o.ToString(); 
ExpandedSubBlockEnd.gif            }

InBlock.gif            
set
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                ViewState[
this.ClientID+"_SetFocusButtonID"= value;
InBlock.gif                
if(value!="")
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    tb.Attributes.Add(
"onkeydown","if(event.keyCode==13){document.getElementById('"+value+"').focus();}");
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        [Bindable(
true),Category("Appearance"),DefaultValue("")] 
InBlock.gif        
public override string ID
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return tb.ID;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
set
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                tb.ID 
= value;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif
InBlock.gif        
//调控件的最大长度属性
InBlock.gif
        [Bindable(true),Category("Appearance"),DefaultValue("")] 
InBlock.gif        
public int MaxLength
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{   
InBlock.gif            
get 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif
InBlock.gif                
object o =ViewState["TextBox_MaxLength"]; 
InBlock.gif                
if(o!=null)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
int maxlength= Convert.ToInt32(o.ToString()); 
InBlock.gif                    AddAttributes(
"maxlength",maxlength.ToString());
InBlock.gif                    
return  maxlength;
ExpandedSubBlockEnd.gif                }

InBlock.gif                
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
return -1;
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }
 
InBlock.gif            
set 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif
InBlock.gif                ViewState[
"TextBox_MaxLength"= value; 
InBlock.gif                AddAttributes(
"maxlength",value.ToString());
ExpandedSubBlockEnd.gif            }
 
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
InBlock.gif        
//调控件的TextMode属性
InBlock.gif
        [Bindable(false),Category("Behavior"),DefaultValue(""),TypeConverter(typeof(TextModeFieldTypeControlsConverter)),Description("要滚动的对象。")] 
InBlock.gif        
public string TextMode  //要进行校验的表达式
ExpandedSubBlockStart.gifContractedSubBlock.gif
        dot.gif
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return tb.TextMode.ToString();
ExpandedSubBlockEnd.gif            }

InBlock.gif            
set
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if (value=="Password")     tb.TextMode =TextBoxMode.Password;
InBlock.gif                
if (value=="MultiLine"
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    tb.TextMode 
=TextBoxMode.MultiLine;
InBlock.gif                    tb.Attributes.Add(
"onkeyup","return isMaxLen(this)");
ExpandedSubBlockEnd.gif                }

InBlock.gif                
if (value=="SingleLine")   tb.TextMode =TextBoxMode.SingleLine;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif        
InBlock.gif        [Bindable(
false),Category("Behavior"),DefaultValue(""),TypeConverter(typeof(RequiredFieldTypeControlsConverter)),Description("要滚动的对象。")] 
InBlock.gif        
public string RequiredFieldType  //要进行校验的表达式
ExpandedSubBlockStart.gifContractedSubBlock.gif
        dot.gif
InBlock.gif            
get 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif
InBlock.gif                
object o =  ViewState["RequiredFieldType"]; 
InBlock.gif                
return (o==null)?"":o.ToString(); 
ExpandedSubBlockEnd.gif            }
 
InBlock.gif            
set 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif
InBlock.gif                ViewState[
"RequiredFieldType"= value; 
InBlock.gif                SetValiateControls();
ExpandedSubBlockEnd.gif            }
 
ExpandedSubBlockEnd.gif        }
 
InBlock.gif        
InBlock.gif    
InBlock.gif        
InBlock.gif        [Bindable(
false),Category("Behavior"),DefaultValue("可为空"),TypeConverter(typeof(CanBeNullControlsConverter)),Description("要滚动的对象。")]
InBlock.gif        
public string CanBeNull  //要表达式是否可以为空
ExpandedSubBlockStart.gifContractedSubBlock.gif
        dot.gif
InBlock.gif            
get 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif
InBlock.gif                
object o =  ViewState["CanBeNull"]; 
InBlock.gif                
return (o==null)?"":o.ToString(); 
ExpandedSubBlockEnd.gif            }
 
InBlock.gif            
set 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif
InBlock.gif                ViewState[
"CanBeNull"= value; 
InBlock.gif                SetValiateControls();
ExpandedSubBlockEnd.gif            }
 
ExpandedSubBlockEnd.gif        }
 
InBlock.gif
InBlock.gif    
InBlock.gif        
//是否进行 ' 号替换
InBlock.gif
        [Bindable(true),Category("Appearance"),DefaultValue("")] 
InBlock.gif        
public bool IsReplaceInvertedComma
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif
InBlock.gif                
object  o= ViewState["IsReplaceInvertedComma"]; 
InBlock.gif                
if(o==null||o.ToString().Trim()=="")
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
return true;
ExpandedSubBlockEnd.gif                }

InBlock.gif                
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif
InBlock.gif                    
return o.ToString().ToLower()=="true"?true:false;    
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }
 
InBlock.gif            
set 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif
InBlock.gif                ViewState[
"IsReplaceInvertedComma"= value; 
ExpandedSubBlockEnd.gif            }
 
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif
InBlock.gif        
InBlock.gif        [Bindable(
true),Category("Appearance"),DefaultValue("")] 
InBlock.gif        
public string ValidationExpression
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif
InBlock.gif                
object  o= ViewState["ValidationExpression"]; 
InBlock.gif                
if(o==null||o.ToString().Trim()=="")
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
return null;
ExpandedSubBlockEnd.gif                }

InBlock.gif                
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif
InBlock.gif                    
return o.ToString().ToLower();
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }
 
InBlock.gif            
set 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif
InBlock.gif                ViewState[
"ValidationExpression"= value; 
ExpandedSubBlockEnd.gif            }
 
ExpandedSubBlockEnd.gif        }

InBlock.gif        
InBlock.gif        [Bindable(
true),Category("Appearance"),DefaultValue("")] 
InBlock.gif        
public string Text 
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif
InBlock.gif                
if(this.RequiredFieldType == "日期")
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
try
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        
return DateTime.Parse(tb.Text).ToString("yyyy-MM-dd");
ExpandedSubBlockEnd.gif                    }

InBlock.gif                    
catch
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        
return "1900-1-1";
ExpandedSubBlockEnd.gif                    }

ExpandedSubBlockEnd.gif                }

InBlock.gif
InBlock.gif                
if(this.RequiredFieldType == "日期时间")
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
try
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        
return DateTime.Parse(tb.Text).ToString("yyyy-MM-dd HH:mm:ss");
ExpandedSubBlockEnd.gif                    }

InBlock.gif                    
catch
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        
return "1900-1-1 00:00:00";
ExpandedSubBlockEnd.gif                    }

ExpandedSubBlockEnd.gif                }

InBlock.gif                
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
return IsReplaceInvertedComma?tb.Text.Replace("'","''").Trim():tb.Text;
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif            
set
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if(this.RequiredFieldType.IndexOf("日期")>=0)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
try
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        tb.Text 
= DateTime.Parse(value).ToString("yyyy-MM-dd");
ExpandedSubBlockEnd.gif                    }

InBlock.gif                    
catch
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        tb.Text 
= "";
ExpandedSubBlockEnd.gif                    }

ExpandedSubBlockEnd.gif                }

InBlock.gif
InBlock.gif                
if(this.RequiredFieldType.IndexOf("日期时间")>=0)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
try
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        tb.Text 
= DateTime.Parse(value).ToString("yyyy-MM-dd HH:mm:ss");
ExpandedSubBlockEnd.gif                    }

InBlock.gif                    
catch
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        tb.Text 
= "";
ExpandedSubBlockEnd.gif                    }

ExpandedSubBlockEnd.gif                }

InBlock.gif                
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    tb.Text
=value;
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif        
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
//调控件的高度属性
InBlock.gif
        [Bindable(false),Category("Appearance"),DefaultValue("")] 
InBlock.gif        
override public Unit Height
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return tb.Height;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
set
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                tb.Height 
= value;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
//调控件的宽度属性
InBlock.gif
        [Bindable(true),Category("Appearance"),DefaultValue("")] 
InBlock.gif        
override public Unit Width
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return tb.Width;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
set
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                tb.Width 
= value;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
private int _rows=5;
InBlock.gif        
//调控件的宽度属性
InBlock.gif
        [Bindable(true),Category("Appearance"),DefaultValue(1)] 
InBlock.gif        
public int  Rows
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return _rows;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
set
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                _rows 
= value;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
private int _cols=45;
InBlock.gif        
//调控件的宽度属性
InBlock.gif
        [Bindable(true),Category("Appearance"),DefaultValue(30)] 
InBlock.gif        
public int  Cols
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return _cols;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
set
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                _cols 
= value;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif    
InBlock.gif
InBlock.gif        
private int _size=45;
InBlock.gif        
//调控件的宽度属性
InBlock.gif
        [Bindable(true),Category("Appearance"),DefaultValue(30)] 
InBlock.gif        
public int  Size
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return _size;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
set
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                _size 
= value;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif    
InBlock.gif
InBlock.gif        
//调控件的宽度属性
InBlock.gif
        [Bindable(true),Category("Appearance"),DefaultValue(true)] 
InBlock.gif        
public override bool  Enabled
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return tb.Enabled;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
set
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                tb.Enabled 
= value;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif    
InBlock.gif
InBlock.gif        
private string _maximumValue = null;
InBlock.gif
InBlock.gif        [Bindable(
true),Category("Appearance"),DefaultValue(null)] 
InBlock.gif        
public string MaximumValue
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return _maximumValue;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
set
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                _maximumValue 
= value;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
private string _minimumValue = null;
InBlock.gif        [Bindable(
true),Category("Appearance"),DefaultValue(null)] 
InBlock.gif        
public string MinimumValue
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return _minimumValue;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
set
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                _minimumValue 
= value;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif
InBlock.gif        
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary> 
InBlock.gif        
/// 将此控件呈现给指定的输出参数。
InBlock.gif        
/// </summary>
ExpandedSubBlockEnd.gif        
/// <param name="output"> 要写出到的 HTML 编写器 </param>

InBlock.gif        protected override void Render(HtmlTextWriter output)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
//output.Write(Text);
InBlock.gif
            if(this.TextMode=="MultiLine")
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                output.WriteLine(
"<script type=\"text/javascript\">");
InBlock.gif                output.WriteLine(
"function isMaxLen(o){");
InBlock.gif                output.WriteLine(
"var nMaxLen=o.getAttribute? parseInt(o.getAttribute(\"maxlength\")):\"\";");
InBlock.gif                output.WriteLine(
" if(o.getAttribute && o.value.length>nMaxLen){");
InBlock.gif                output.WriteLine(
" o.value=o.value.substring(0,nMaxLen)");
InBlock.gif                output.WriteLine(
"}}</script>");
InBlock.gif
InBlock.gif                
this.AddAttributes("rows",Rows.ToString());
InBlock.gif                
this.AddAttributes("cols",Cols.ToString());
ExpandedSubBlockEnd.gif            }

InBlock.gif            
else
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if(this.Width.Value.ToString()!="")
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
if(Width.Type.ToString()!="")
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        
this.AddAttributes("SIZE",(Width.Value/10).ToString()+(Width.Type.ToString()=="Pixel"?"px":"%"));
ExpandedSubBlockEnd.gif                    }

InBlock.gif                
InBlock.gif                    
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        
this.AddAttributes("SIZE",(Width.Value/10).ToString()+"px");
ExpandedSubBlockEnd.gif                    }

ExpandedSubBlockEnd.gif                }

InBlock.gif
InBlock.gif                
if(this.Size.ToString()!="")
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
this.AddAttributes("SIZE",this.Size.ToString());
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif            
InBlock.gif            
//当指定了输入框的最小或最大值时,则加入校验范围项
InBlock.gif
            if(this.MaximumValue!=null||this.MinimumValue!=null)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                rangevalidator.ControlToValidate
=tb.ID;
InBlock.gif                rangevalidator.Type
=ValidationDataType.Double;
InBlock.gif                rangevalidator.ForeColor
=System.Drawing.Color.Black;
InBlock.gif
InBlock.gif                
if(this.MaximumValue!=null&&this.MinimumValue!=null)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    rangevalidator.MaximumValue
=this.MaximumValue;
InBlock.gif                    rangevalidator.MinimumValue
=this.MinimumValue;
InBlock.gif                    rangevalidator.ErrorMessage
=" 当前输入数据应在"+this.MinimumValue+""+this.MaximumValue+"之间!";
ExpandedSubBlockEnd.gif                }

InBlock.gif                
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
if(this.MaximumValue!=null)
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        rangevalidator.MaximumValue
=this.MaximumValue;
InBlock.gif                        rangevalidator.ErrorMessage
=" 当前输入数据允许最大值为"+this.MaximumValue;
ExpandedSubBlockEnd.gif                    }

InBlock.gif                    
if(this.MinimumValue!=null)
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        rangevalidator.MinimumValue
=this.MinimumValue;
InBlock.gif                        rangevalidator.ErrorMessage
=" 当前输入数据允许最小值为"+this.MinimumValue;
ExpandedSubBlockEnd.gif                    }

ExpandedSubBlockEnd.gif                }

InBlock.gif                rangevalidator.Display
=ValidatorDisplay.Static;
InBlock.gif                
this.Controls.Add(rangevalidator);
ExpandedSubBlockEnd.gif            }

InBlock.gif
InBlock.gif            
InBlock.gif            RenderChildren(output);
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
IPostBackDataHandler 成员#region IPostBackDataHandler 成员
InBlock.gif
InBlock.gif 
InBlock.gif
InBlock.gif        
public void RaisePostDataChangedEvent()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{}
InBlock.gif
InBlock.gif
InBlock.gif        
public bool LoadPostData(string postDataKey, System.Collections.Specialized.NameValueCollection postCollection)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
string presentValue = this.tb.Text;
InBlock.gif            
string postedValue = postCollection[postDataKey];
InBlock.gif
InBlock.gif            
if (!presentValue.Equals(postedValue))//如果回发数据不等于原有数据
ExpandedSubBlockStart.gifContractedSubBlock.gif
            dot.gif{
InBlock.gif                
this.Text = postedValue;
InBlock.gif                
this.tb.Text = postedValue;
InBlock.gif                
return true;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
return false;
InBlock.gif
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
ExpandedSubBlockEnd.gif    }

InBlock.gif
InBlock.gif    
public class RequiredFieldTypeControlsConverter:StringConverter
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif        
public RequiredFieldTypeControlsConverter()    dot.gif{}
InBlock.gif
InBlock.gif        
public override bool GetStandardValuesSupported(ITypeDescriptorContext context) 
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif
InBlock.gif            
return true
ExpandedSubBlockEnd.gif        }
 
InBlock.gif        
public override System.ComponentModel.TypeConverter.StandardValuesCollection GetStandardValues(ITypeDescriptorContext context) 
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif
InBlock.gif            ArrayList controlsArray 
= new ArrayList(); 
InBlock.gif            controlsArray.Add(
"暂无校验"); 
InBlock.gif            controlsArray.Add(
"数据校验");
InBlock.gif            controlsArray.Add(
"电子邮箱");
InBlock.gif            controlsArray.Add(
"移动手机"); 
InBlock.gif            controlsArray.Add(
"家用电话"); 
InBlock.gif            controlsArray.Add(
"身份证号码"); 
InBlock.gif            controlsArray.Add(
"网页地址"); 
InBlock.gif            controlsArray.Add(
"日期"); 
InBlock.gif            controlsArray.Add(
"日期时间"); 
InBlock.gif            controlsArray.Add(
"金额"); 
InBlock.gif            controlsArray.Add(
"IP地址"); 
InBlock.gif            controlsArray.Add(
"IP地址带端口"); 
InBlock.gif            
return new StandardValuesCollection(controlsArray); 
InBlock.gif             
ExpandedSubBlockEnd.gif        }
 
InBlock.gif        
public override bool GetStandardValuesExclusive(ITypeDescriptorContext context) 
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif
InBlock.gif            
return false
ExpandedSubBlockEnd.gif        }
 
ExpandedSubBlockEnd.gif    }

InBlock.gif
InBlock.gif
InBlock.gif    
public class CanBeNullControlsConverter:StringConverter
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif        
public CanBeNullControlsConverter()    dot.gif{}
InBlock.gif
InBlock.gif        
public override bool GetStandardValuesSupported(ITypeDescriptorContext context) 
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif
InBlock.gif            
return true
ExpandedSubBlockEnd.gif        }
 
InBlock.gif    
InBlock.gif        
public override System.ComponentModel.TypeConverter.StandardValuesCollection GetStandardValues(ITypeDescriptorContext context) 
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif
InBlock.gif            ArrayList controlsArray 
= new ArrayList(); 
InBlock.gif            controlsArray.Add(
"可为空"); 
InBlock.gif            controlsArray.Add(
"必填"); 
InBlock.gif        
InBlock.gif             
return new StandardValuesCollection(controlsArray); 
InBlock.gif             
ExpandedSubBlockEnd.gif        }
 
InBlock.gif
InBlock.gif        
public override bool GetStandardValuesExclusive(ITypeDescriptorContext context) 
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif
InBlock.gif            
return false
ExpandedSubBlockEnd.gif        }
 
ExpandedSubBlockEnd.gif    }

InBlock.gif
InBlock.gif
InBlock.gif    
public class FormControlsConverter:StringConverter 
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif
InBlock.gif        
public FormControlsConverter() 
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif
ExpandedSubBlockEnd.gif        }
 
InBlock.gif
InBlock.gif        
public override bool GetStandardValuesSupported(ITypeDescriptorContext context) 
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif
InBlock.gif            
return true
ExpandedSubBlockEnd.gif        }
 
InBlock.gif
InBlock.gif        
public override System.ComponentModel.TypeConverter.StandardValuesCollection GetStandardValues(ITypeDescriptorContext context) 
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif
InBlock.gif            ControlCollection Controls 
= ((Page)context.Container.Components[0]).Controls; 
InBlock.gif            ArrayList controlsArray 
= new ArrayList(); 
InBlock.gif            
for(int i = 0 ;i < Controls.Count ; i++
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif
InBlock.gif                
if((Controls[i] is HtmlTable 
InBlock.gif                    
|| Controls[i] is HtmlForm 
InBlock.gif                    
|| Controls[i] is HtmlGenericControl 
InBlock.gif                    
|| Controls[i] is HtmlImage 
InBlock.gif                    
|| Controls[i] is Label 
InBlock.gif                    
|| Controls[i] is DataGrid 
InBlock.gif                    
|| Controls[i] is DataList 
InBlock.gif                    
|| Controls[i] is Table 
InBlock.gif                    
|| Controls[i] is Repeater 
InBlock.gif                    
|| Controls[i] is Image 
InBlock.gif                    
|| Controls[i] is Panel 
InBlock.gif                    
|| Controls[i] is PlaceHolder 
InBlock.gif                    
|| Controls[i] is Calendar 
InBlock.gif                    
|| Controls[i] is AdRotator 
InBlock.gif                    
|| Controls[i] is Xml 
InBlock.gif                    )) 
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif
InBlock.gif                    controlsArray.Add(Controls[i].ClientID); 
ExpandedSubBlockEnd.gif                }
 
ExpandedSubBlockEnd.gif            }
 
InBlock.gif            
return new StandardValuesCollection(controlsArray); 
InBlock.gif             
ExpandedSubBlockEnd.gif        }

InBlock.gif 
InBlock.gif        
public override bool GetStandardValuesExclusive(ITypeDescriptorContext context) 
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif
InBlock.gif            
return false
ExpandedSubBlockEnd.gif        }
 
ExpandedSubBlockEnd.gif    }
 
InBlock.gif
InBlock.gif
InBlock.gif    
public class TextModeFieldTypeControlsConverter:StringConverter 
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif
InBlock.gif        
public TextModeFieldTypeControlsConverter() 
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif
ExpandedSubBlockEnd.gif        }
 
InBlock.gif
InBlock.gif        
public override bool GetStandardValuesSupported(ITypeDescriptorContext context) 
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif
InBlock.gif            
return true
ExpandedSubBlockEnd.gif        }
 
InBlock.gif
InBlock.gif        
public override System.ComponentModel.TypeConverter.StandardValuesCollection GetStandardValues(ITypeDescriptorContext context) 
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif
InBlock.gif            ArrayList controlsArray 
= new ArrayList(); 
InBlock.gif            controlsArray.Add(
"Password"); 
InBlock.gif            controlsArray.Add(
"SingleLine"); 
InBlock.gif            controlsArray.Add(
"MultiLine"); 
InBlock.gif        
InBlock.gif             
return new StandardValuesCollection(controlsArray); 
InBlock.gif             
ExpandedSubBlockEnd.gif        }
 
InBlock.gif        
public override bool GetStandardValuesExclusive(ITypeDescriptorContext context) 
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif
InBlock.gif            
return false
ExpandedSubBlockEnd.gif        }
 
ExpandedSubBlockEnd.gif    }
 
InBlock.gif    
ExpandedBlockEnd.gif}

转载于:https://www.cnblogs.com/andysun/archive/2007/06/07/775449.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值