function maskDate(sValue, sType)
dim zMonth
zMonth = array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December")
if len(trim(sValue)) = 0 then
maskDate = ""
setViewState false
elseif not(isDate(sValue)) then
maskDate = "# INVALID DATE ENTERED #"
setViewState true
else
select case (sType)
case "medium"
maskDate = day(dateValue(sValue)) & "-" & left(zMonth(month(dateValue(sValue)) - 1), 3) & "-" & year(dateValue(sValue))
case "long"
maskDate = zMonth(month(dateValue(sValue)) - 1) & " " & day(dateValue(sValue)) & ", " & year(dateValue(sValue))
case else
maskDate = formatDateTime(sValue, vbShortDate)
end select
setViewState false
end if
end function
可以看到处理方式是将文本框中的字符串格式化,如果格式化成功则显示为格式化后的字符串,否则显示"# INVALID DATE ENTERED"。其他的方法与之类似,像maskCurrency, maskSSN什么的。protected override void Render(HtmlTextWriter output)
{
output.WriteBeginTag("input");
output.WriteAttribute("type","hidden");
output.WriteAttribute("value","");
output.WriteAttribute("id","__"+this.UniqueID);
output.WriteAttribute("name","__"+this.UniqueID);
output.Write(HtmlTextWriter.TagRightChar);
base.Render(output);
}
本文地址:http://com.8s8s.com/it/it41952.htm