在网上找到一个js的日期选择控件,然后把它加工成自定义控件了。

在网上找到一个js的日期选着控件
calendar.htc

ContractedBlock.gif ExpandedBlockStart.gif
None.gif<public:component tagname="calendar">
None.gif    
<public:attach event="onfocus" onevent="show()" />
None.gif    
<public:attach event="onblur" onevent="hide()" />
None.gif    
None.gif    
<public:property name="format" />
None.gif    
<public:property name="status" />
None.gif    
None.gif    
<public:method  name="showCurrentDate" />
None.gif    
<public:method  name="hide" />
None.gif    
<public:method  name="showMore" />
None.gif    
None.gif    
<script>
None.gif    
if (format==null)
None.gif        format 
= "yyyy-mm-dd";
None.gif        
ExpandedBlockStart.gifContractedBlock.gif    
function calculateSumOffset(item, offsetName) dot.gif{
InBlock.gif        
var totalOffset = 0;
ExpandedSubBlockStart.gifContractedSubBlock.gif        
do dot.gif{
InBlock.gif            totalOffset 
+= eval('item.'+offsetName);
InBlock.gif            item 
= eval('item.offsetParent');
ExpandedSubBlockEnd.gif        }
 while (item != null);
InBlock.gif        
return totalOffset;
ExpandedBlockEnd.gif    }

None.gif    
ExpandedBlockStart.gifContractedBlock.gif    
function hideElement(elmID) dot.gif{
InBlock.gif        
var leftX, rightX, topY, bottomY, objLeft, objTop;
ExpandedSubBlockStart.gifContractedSubBlock.gif        
for (i = 0; i < document.all.tags(elmID).length; i++dot.gif{
InBlock.gif            obj 
= document.all.tags(elmID)[i];
InBlock.gif            
if (! obj || ! obj.offsetParent)
InBlock.gif                
continue;
InBlock.gif    
InBlock.gif            
// Find the element's offsetTop and offsetLeft relative to the BODY tag.
InBlock.gif
            leftX    = calculateSumOffset(tblMonthView, 'offsetLeft');
InBlock.gif            rightX    
= leftX + tblMonthView.offsetWidth;
InBlock.gif            topY    
= calculateSumOffset(tblMonthView, 'offsetTop');
InBlock.gif            bottomY 
= topY + tblMonthView.offsetHeight;
InBlock.gif            objLeft    
= calculateSumOffset(obj, 'offsetLeft');
InBlock.gif            objTop    
= calculateSumOffset(obj, 'offsetTop');
InBlock.gif    
InBlock.gif            
if (leftX > (objLeft + obj.offsetWidth) || objLeft > rightX) ;
InBlock.gif            
else if (objTop > bottomY) ;
InBlock.gif            
else obj.style.visibility = "hidden";
ExpandedSubBlockEnd.gif        }

ExpandedBlockEnd.gif    }

None.gif    
ExpandedBlockStart.gifContractedBlock.gif    
function showElement(elmID) dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif        
for (i = 0; i < document.all.tags(elmID).length; i++dot.gif{
InBlock.gif            obj 
= document.all.tags(elmID)[i];
InBlock.gif            
if (! obj || ! obj.offsetParent)
InBlock.gif                
continue;
InBlock.gif            obj.style.visibility 
= "";
ExpandedSubBlockEnd.gif        }

ExpandedBlockEnd.gif    }

None.gif
None.gif    
var arrWeekName = new Array("","","","","","","");
None.gif    
var today = new Date();
None.gif    
var currentYear, currentMonth, inputYear, inputMonth, inputDate;
None.gif    currentYear 
= inputYear = today.getYear();
None.gif    currentMonth 
= inputMonth = today.getMonth();
None.gif    inputDate 
= today.getDate();
None.gif
None.gif    status 
= false;
None.gif    
None.gif    
var tblMonthView, trWeek, tdToday;
None.gif    
var tblShowDay;
None.gif    
var spanCurrentMonth, spanCurrentYear;
None.gif    
var divMore;
None.gif
None.gif    
var strHTML = '<table id="MonthView' + uniqueID + '" cellpadding=0 cellspacing=0  lang=ch onselectstart="return false" onmouseover="' + uniqueID + '.status=true;" onmouseout="' + uniqueID + '.status=false;" style="position:absolute; display:none; background:#FFFFFF; border:1 solid black;width:220;cursor:hand;">'
None.gif        
+ '<tr>'
None.gif        
+ '    <td>'
None.gif        
+ '        <table width="100%" border=0 cellpadding=1 cellspacing=1 id="ShowDay' + uniqueID + '" style="font-size:9pt;">'
None.gif        
+ '        <tr  align="center">'
None.gif        
+ '            <td style="font-family:webdings;font-size:9pt;background:#A4B9D7;" onmouseover="this.style.color=\'white\'" onmouseout="this.style.color=\'black\'" onclick="' + uniqueID + '.showCurrentDate(\'py\')">33td>'
None.gif        
+ '            <td style="font-family:webdings;font-size:9pt;background:#A4B9D7;" onmouseover="this.style.color=\'white\'" onmouseout="this.style.color=\'black\'" onclick="' + uniqueID + '.showCurrentDate(\'pm\')">3td>'
None.gif        
+ '            <td colspan="3" style="color:black;font-family:宋体;font-weight:bold;" nowarp>'
None.gif        
+ '                <span id="CurrentYear' + uniqueID + '" style="text-decoration:underline;" onmouseover="this.style.color=\'white\'" onmouseout="this.style.color=\'black\'" onclick="' + uniqueID + '.showMore(1990,2020,this.innerHTML)">span>&nbsp;年'
None.gif        
+ '                <span id="CurrentMonth' + uniqueID + '" style="text-decoration:underline;" onmouseover="this.style.color=\'white\'" onmouseout="this.style.color=\'black\'" onclick="' + uniqueID + '.showMore(1,12,this.innerHTML)">span>&nbsp;月td>'
None.gif        
+ '            <td style="font-family:webdings;font-size:9pt;background:#A4B9D7;" onmouseover="this.style.color=\'white\'" onmouseout="this.style.color=\'black\'" onclick="' + uniqueID + '.showCurrentDate(\'nm\')">4td>'
None.gif        
+ '            <td style="font-family:webdings;font-size:9pt;background:#A4B9D7;" onmouseover="this.style.color=\'white\'" onmouseout="this.style.color=\'black\'" onclick="' + uniqueID + '.showCurrentDate(\'ny\')">44td>'
None.gif        
+ '        tr>'
None.gif        
+ '        <tr id="Week' + uniqueID + '" style="font-size:9pt; color:black; text-align:center;"><td>td><td>td><td>td><td>td><td>td><td>td><td>td>tr>'
None.gif        
+ '        <tr><td colspan=7 style="background-color:black; height:1pt;">td>tr>'
None.gif        
+ '        table>'
None.gif        
+ '    td>'
None.gif        
+ 'tr>'
None.gif        
+ '<tr><td style="background-color:black; height:1pt;">td>tr>'
None.gif        
+ '<tr>'
None.gif        
+ '    <td>'
None.gif        
+ '        <table width="100%" border=0 cellpadding=1 cellspacing=1>'
None.gif        
+ '        <tr style="font-size:9pt; color:black;">'
None.gif        
+ '            <td id="Today' + uniqueID + '">td>'
None.gif        
+ '            <td id="Button' + uniqueID + '" style="text-align:right;" onclick="' + uniqueID + '.status=false;' + uniqueID + '.hide();">[关闭]td>'
None.gif        
+ '        tr>'
None.gif        
+ '        table>'
None.gif        
+ '    td>'
None.gif        
+ '    tr>'
None.gif        
+ 'table>'
None.gif        
+ '<div id="More' + uniqueID + '" style="display:none; cursor:hand; font:9px verdana; width:80px; position:absolute; border:1px solid #425E87; overflow-y:scroll; overflow-x:hidden; background-color:#fff; FILTER:progid:DXImageTransform.Microsoft.Shadow(Color=#999999,offX=10,offY=10,direction=120,Strength=5); SCROLLBAR-FACE-COLOR: #E5E9F2; SCROLLBAR-HIGHLIGHT-COLOR:#E5E9F2; SCROLLBAR-SHADOW-COLOR:#A4B9D7; SCROLLBAR-3DLIGHT-COLOR: #A4B9D7; SCROLLBAR-ARROW-COLOR:#000000; SCROLLBAR-TRACK-COLOR:#eeeee6; SCROLLBAR-DARKSHADOW-COLOR: #ffffff;">div>';
None.gif        
None.gif    element.insertAdjacentHTML(
"afterEnd",strHTML);    
None.gif        
None.gif    tblMonthView 
= eval("MonthView" + uniqueID);
None.gif    trWeek 
= eval("Week" + uniqueID);
None.gif    tdToday 
= eval("Today" + uniqueID);
None.gif    tblShowDay 
= eval("ShowDay" + uniqueID);
None.gif    spanCurrentMonth 
= eval("CurrentMonth" + uniqueID);
None.gif    spanCurrentYear 
= eval("CurrentYear" + uniqueID);
None.gif    divMore 
= eval("More" + uniqueID);
None.gif    
None.gif    
for (var i=0; i<arrWeekName.length; i++)
None.gif        trWeek.cells[i].innerHTML 
= arrWeekName[i];
None.gif    
None.gif    tdToday.attachEvent(
"onclick", setTodayValue);
None.gif    
ExpandedBlockStart.gifContractedBlock.gif    
function formatDate(y, m, d,  strFormat) dot.gif{
InBlock.gif        
var dm = (m>=10?m:"0" + m), dd = (d>=10?d:"0" + d);
InBlock.gif        
return strFormat.replace(/yyyy/ig, y).replace(/mm/ig, dm).replace(/dd/ig, dd).replace(/m/ig, m).replace(/d/ig, d);
ExpandedBlockEnd.gif    }

ExpandedBlockStart.gifContractedBlock.gif    
function setCaption()dot.gif{
InBlock.gif        spanCurrentYear.innerHTML 
= currentYear;
InBlock.gif        spanCurrentMonth.innerHTML 
= formatDate(0, currentMonth + 10"mm");
ExpandedBlockEnd.gif    }

ExpandedBlockStart.gifContractedBlock.gif    
function bulidDay()dot.gif{
InBlock.gif        
var arrMonthDay = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
InBlock.gif        
if ((currentYear % 400 == 0|| ((currentYear % 100!=0&& (currentYear % 4==0)))
InBlock.gif            arrMonthDay[
1= 29;
InBlock.gif        
InBlock.gif        
while (tblShowDay.rows.length>3)
InBlock.gif            tblShowDay.deleteRow(
3);
InBlock.gif        
InBlock.gif        firstDay 
= new Date(currentYear,currentMonth,1);
InBlock.gif        weekDay 
= firstDay.getDay();
InBlock.gif
InBlock.gif        prevMonthEnd 
= arrMonthDay[(currentMonth>0?currentMonth - 1:11)];
InBlock.gif        prevMonthStart 
= prevMonthEnd - weekDay;
InBlock.gif        thisMonthStart 
= 0;
InBlock.gif        thisMonthEnd 
= arrMonthDay[currentMonth];
InBlock.gif        nextMonthStart 
= 0;
InBlock.gif        
InBlock.gif        
var d = new Date();
InBlock.gif        
var nowDate = d.getDate();
InBlock.gif        
var nowMonth = d.getMonth();
InBlock.gif        
var nowYear = d.getYear();
InBlock.gif                    
InBlock.gif        
var i, j;
ExpandedSubBlockStart.gifContractedSubBlock.gif        
for (i=0; i<6; i++dot.gif{
InBlock.gif            tempRow 
= tblShowDay.insertRow();
ExpandedSubBlockStart.gifContractedSubBlock.gif            
for (j=0; j<7; j++dot.gif{
InBlock.gif                tempCell 
= tempRow.insertCell();
InBlock.gif                tempCell.style.cssText 
= "border:1pt solid white; font-size:9pt; color:#808080; text-align:center;";
InBlock.gif                
InBlock.gif                
//填充当月1号以前的日期
InBlock.gif
                if (prevMonthStart<prevMonthEnd)
InBlock.gif                    tempCell.innerHTML 
= ++prevMonthStart;
InBlock.gif                
//填充本月日期
ExpandedSubBlockStart.gifContractedSubBlock.gif
                else if (thisMonthStart<thisMonthEnd) dot.gif{
InBlock.gif                    tempCell.style.color 
= ((j==0 || j==6)?"red":"black");
InBlock.gif                    tempCell.innerHTML 
= ++thisMonthStart;
InBlock.gif                    tempCell.onclick 
= action;
InBlock.gif                    tempCell.onmouseover 
= mouseover;
InBlock.gif                    tempCell.onmouseout 
= mouseout;
InBlock.gif                    
InBlock.gif                    
if (nowYear==currentYear && nowMonth==currentMonth && nowDate==thisMonthStart)
InBlock.gif                        tempCell.style.border 
= "1pt solid red";
InBlock.gif                    
if (inputYear==currentYear && inputMonth==currentMonth && inputDate==thisMonthStart)
InBlock.gif                        tempCell.bgColor 
= "menu";
ExpandedSubBlockEnd.gif                }

InBlock.gif                
//填充下月日期
InBlock.gif
                else tempCell.innerHTML = ++nextMonthStart;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

ExpandedBlockEnd.gif    }

ExpandedBlockStart.gifContractedBlock.gif    
function setTodayValue()dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif        
with (new Date()) dot.gif{
InBlock.gif            
var strDate = formatDate(getYear(), (getMonth() + 1), getDate(), "yyyy-mm-dd");
InBlock.gif            tdToday.innerHTML 
= "今日:" + strDate;
InBlock.gif            element.value 
= strDate;
ExpandedSubBlockEnd.gif        }

InBlock.gif        
InBlock.gif        status 
= false;
InBlock.gif        hide();
ExpandedBlockEnd.gif    }

ExpandedBlockStart.gifContractedBlock.gif    
function setToday()dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif        
with (new Date()) dot.gif{
InBlock.gif            tdToday.innerHTML 
= "今日:" + formatDate(getYear(), (getMonth() + 1), getDate(), "yyyy-mm-dd");
ExpandedSubBlockEnd.gif        }

ExpandedBlockEnd.gif    }

ExpandedBlockStart.gifContractedBlock.gif    
function showCurrentDate(cmd) dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif        
switch (cmd) dot.gif{
InBlock.gif        
case "py":currentYear--break;
InBlock.gif        
case "ny":currentYear++break;
ExpandedSubBlockStart.gifContractedSubBlock.gif        
case "pm":if (--currentMonth<0dot.gif{
InBlock.gif                    currentMonth 
= 11;
InBlock.gif                    currentYear
--;
ExpandedSubBlockEnd.gif                }

InBlock.gif                
break;
ExpandedSubBlockStart.gifContractedSubBlock.gif        
case "nm":if (++currentMonth>11dot.gif{
InBlock.gif                    currentMonth 
= 0;
InBlock.gif                    currentYear
++;
ExpandedSubBlockEnd.gif                }

InBlock.gif                
break;
ExpandedSubBlockEnd.gif        }

InBlock.gif        setCaption();
InBlock.gif        bulidDay();
InBlock.gif        setToday();
InBlock.gif
InBlock.gif        
//element.focus();
InBlock.gif
        hideElement("SELECT");
InBlock.gif        hideElement(
"OBJECT");
ExpandedBlockEnd.gif    }

ExpandedBlockStart.gifContractedBlock.gif    
function show() dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif        
if (!status) dot.gif{
InBlock.gif            
var ParseRegx = new RegExp(format.replace(/yyyy/g, "(\\d{4})").replace(/mm/g, "(\\d{2})").replace(/dd/g, "(\\d{2})"), "g");
InBlock.gif            
var t = element.value.replace(ParseRegx, "$2-$3-$1");
InBlock.gif            
var d = new Date(t);
InBlock.gif            
if (isNaN(d))
InBlock.gif                d 
= new Date();
InBlock.gif            
InBlock.gif            inputYear 
= currentYear = d.getYear();
InBlock.gif            inputMonth 
= currentMonth = d.getMonth();
InBlock.gif            inputDate 
= d.getDate();
InBlock.gif            element.value 
= formatDate(inputYear, (inputMonth + 1), inputDate, format);
InBlock.gif            
InBlock.gif            setCaption();
InBlock.gif            bulidDay();
InBlock.gif            setToday();
InBlock.gif            
InBlock.gif            tblMonthView.style.top 
= calculateSumOffset(element, "offsetTop"+ element.offsetHeight;
InBlock.gif            tblMonthView.style.left 
= calculateSumOffset(element, "offsetLeft");
InBlock.gif            
InBlock.gif            tblMonthView.style.display 
= "block";
InBlock.gif            element.focus();
InBlock.gif            hideElement(
"SELECT");
InBlock.gif            hideElement(
"OBJECT");
ExpandedSubBlockEnd.gif        }

ExpandedBlockEnd.gif    }

ExpandedBlockStart.gifContractedBlock.gif    
function hide() dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif        
if (!status) dot.gif{
InBlock.gif            showElement(
"SELECT");
InBlock.gif            showElement(
"OBJECT");
InBlock.gif            tblMonthView.style.display 
= "none";
ExpandedSubBlockEnd.gif        }

ExpandedBlockEnd.gif    }

ExpandedBlockStart.gifContractedBlock.gif    
function mouseover()dot.gif{
InBlock.gif        
this.bgColor="#9999FF";
ExpandedBlockEnd.gif    }

ExpandedBlockStart.gifContractedBlock.gif    
function mouseout()dot.gif{
InBlock.gif        
if (inputYear==currentYear && inputMonth==currentMonth && inputDate==this.innerHTML)
InBlock.gif            
this.bgColor="menu";
InBlock.gif        
else
InBlock.gif            
this.bgColor="#FFFFFF";
ExpandedBlockEnd.gif    }

ExpandedBlockStart.gifContractedBlock.gif    
function action()dot.gif{
InBlock.gif        inputYear 
= currentYear;
InBlock.gif        inputMonth 
= currentMonth;
InBlock.gif        inputDate 
= this.innerHTML;
InBlock.gif        bulidDay();
InBlock.gif        element.value 
= formatDate(inputYear, (inputMonth + 1), inputDate, format);
InBlock.gif        
InBlock.gif        status 
= false;
InBlock.gif        hide();
ExpandedBlockEnd.gif    }

None.gif    
None.gif    
var cssNotSelect = "padding:0px 0px 2px 5px; width:100%; color:#000; letter-spacing:2px; text-decoration:none;",
None.gif        cssSelected 
= "background-color:#00006C;color:#fff;padding:0px 0px 2px 5px; width:100%; letter-spacing:2px; text-decoration:none;";
None.gif        
ExpandedBlockStart.gifContractedBlock.gif    
function showMore(starNum,endNum,selectedValue)dot.gif{
InBlock.gif        
var obj = window.event.srcElement;
InBlock.gif        
var selectedIndex = selectedValue - starNum;
InBlock.gif
InBlock.gif        divMore.style.height 
= 0;
InBlock.gif        divMore.style.top 
= calculateSumOffset(obj, "offsetTop"+ obj.offsetHeight;
InBlock.gif        divMore.style.left 
= calculateSumOffset(obj, "offsetLeft");
InBlock.gif            
InBlock.gif        divMore.selectedIndex 
= selectedIndex;
ExpandedSubBlockStart.gifContractedSubBlock.gif        divMore.onclick 
= function() dot.gif{
InBlock.gif            
var selectedObj = window.event.srcElement;
ExpandedSubBlockStart.gifContractedSubBlock.gif            
if"nobr" == selectedObj.tagName.toLowerCase() && divMore.contains(selectedObj)) dot.gif{
InBlock.gif                
var tmp = parseInt(selectedObj.innerHTML, 10);
ExpandedSubBlockStart.gifContractedSubBlock.gif                
if(parseInt(obj.innerHTML, 10!= tmp) dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
if (tmp>12dot.gif{
InBlock.gif                        obj.innerHTML 
= tmp;
InBlock.gif                        currentYear 
= tmp;
ExpandedSubBlockStart.gifContractedSubBlock.gif                    }
 else dot.gif{
InBlock.gif                        obj.innerHTML 
= formatDate(0, tmp, 0"mm");
InBlock.gif                        currentMonth 
= tmp - 1;
ExpandedSubBlockEnd.gif                    }

InBlock.gif                    
InBlock.gif                    showCurrentDate(
"");
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        divMore.onlosecapture 
= alert
InBlock.gif        
var strHTML = "";
ExpandedSubBlockStart.gifContractedSubBlock.gif        
for(var i=starNum;i<=endNum;i++)dot.gif{
InBlock.gif            strHTML 
+= ""this.parentNode.getElementsByTagName('nobr')[this.parentNode.selectedIndex].style.cssText='" + cssNotSelect + "';this.style.cssText='" + cssSelected + "'\"  οnmοuseοut=\"this.style.cssText='" + cssNotSelect + "'\" style=\"" + cssNotSelect + "\">"+i+"
" 
ExpandedSubBlockEnd.gif        }

InBlock.gif        divMore.innerHTML 
= strHTML;
InBlock.gif
InBlock.gif        showBox(
150);
ExpandedBlockEnd.gif    }

None.gif    
ExpandedBlockStart.gifContractedBlock.gif    
function showBox(iHeight) dot.gif{
InBlock.gif        divMore.style.height 
=1;
InBlock.gif        divMore.style.display 
= "block";
InBlock.gif        window.clearInterval(divMore.timeHandle);
InBlock.gif        divMore.timeHandle 
= window.setInterval(interValHandle,1);
InBlock.gif    
InBlock.gif        
var s = 0,t = 1;
ExpandedSubBlockStart.gifContractedSubBlock.gif        
function interValHandle() dot.gif{
InBlock.gif            divMore.scrollTop 
= 1000000;
InBlock.gif            s 
= s + t*t;
InBlock.gif            t 
+= 0.5;
InBlock.gif            divMore.style.height 
= parseInt(divMore.style.height) + Math.floor(s);
InBlock.gif            
//divMore.style.width = 65 / iHeight * divMore.offsetHeight;
ExpandedSubBlockStart.gifContractedSubBlock.gif
            if( divMore.offsetHeight > iHeight ) dot.gif{
InBlock.gif                window.clearInterval(divMore.timeHandle);
InBlock.gif                divMore.style.height 
= iHeight;
InBlock.gif                divMore.scrollTop 
= divMore.childNodes[0].offsetHeight * divMore.selectedIndex;
InBlock.gif                divMore.getElementsByTagName(
"nobr")[divMore.selectedIndex].style.cssText = cssSelected;
InBlock.gif                window.document.attachEvent(
"onclick",
ExpandedSubBlockStart.gifContractedSubBlock.gif                    divMore.hide 
= function() dot.gif{
InBlock.gif                        divMore.style.display 
= "none";
InBlock.gif                        window.document.detachEvent(
"onclick", divMore.hide);
ExpandedSubBlockEnd.gif                    }

InBlock.gif                );
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

ExpandedBlockEnd.gif    }

None.gif    
script>
None.gif
public:component>

加工成自定义控件
InputCalendar.cs
None.gif using  System;
None.gif
using  System.ComponentModel;
None.gif
using  System.Drawing;
None.gif
using  System.Web;
None.gif
using  System.Web.UI;
None.gif
using  System.Web.UI.WebControls;
None.gif[assembly: TagPrefix(
" Jxmstc " " Jxmstc " )]
None.gif
namespace  Jxmstc
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    [
InBlock.gif    DefaultProperty(
"Text"),
InBlock.gif    ToolboxData(
@"<{0}:InputCalender 
InBlock.gif    ID='iptCad'
InBlock.gif    runat='server'>
")
InBlock.gif    ]
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//// 
InBlock.gif    
/// 日期输入控件,
ExpandedSubBlockEnd.gif    
/// 

InBlock.gif    public class InputCalender : CompositeControl
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
private TextBox _textBox;
InBlock.gif         [
InBlock.gif         Bindable(
true), Category("Appearance"), DefaultValue(""), Description("获取或设置文本框输入文本")
InBlock.gif        ]
InBlock.gif        
public string Text
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                EnsureChildControls();
InBlock.gif                
return _textBox.Text;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
set
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                EnsureChildControls();
InBlock.gif                _textBox.Text 
= value;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        [
InBlock.gif        Bindable(
true), Category("Appearance"), DefaultValue(""), Description("长度")
InBlock.gif        ]
InBlock.gif        
public int CssWidth
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif            
get dot.gifreturn (ViewState["Length"!= null ? (int)ViewState["Length"] : 100); }
ExpandedSubBlockStart.gifContractedSubBlock.gif            
set dot.gif{ ViewState["Length"= value; }        
ExpandedSubBlockEnd.gif        }

InBlock.gif        [
InBlock.gif        Bindable(
true), Category("Appearance"), DefaultValue(""), Description("最大输入长度")
InBlock.gif        ]
InBlock.gif        
public int MaxLength
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif            
get dot.gifreturn (ViewState["MaxLength"!= null ? (int)ViewState["MaxLength"] :10); }
ExpandedSubBlockStart.gifContractedSubBlock.gif            
set dot.gif{ ViewState["MaxLength"= value; }    
ExpandedSubBlockEnd.gif        }

InBlock.gif        [
InBlock.gif        Bindable(
true), Category("Appearance"), DefaultValue(""), Description("是否只读")
InBlock.gif       ]
InBlock.gif        
public bool ReadOnly
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif            
get dot.gifreturn (ViewState["ReadOnly"!= null ? (bool)ViewState["ReadOnly"] : false); }
ExpandedSubBlockStart.gifContractedSubBlock.gif            
set dot.gif{ ViewState["ReadOnly"= value; }        
ExpandedSubBlockEnd.gif        }

InBlock.gif        [
InBlock.gif        Bindable(
true), Category("Appearance"), DefaultValue(""), Description("脚本资源文件地址")
InBlock.gif        ]
InBlock.gif        
public string ScriptUrl
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif            
get dot.gifreturn (ViewState["ScriptUrl"!= null ? (string)ViewState["ScriptUrl"] :""); }
ExpandedSubBlockStart.gifContractedSubBlock.gif            
set dot.gif{ ViewState["ScriptUrl"= value; }    
ExpandedSubBlockEnd.gif        }

InBlock.gif        
public InputCalender()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
//this.ScriptUrl = GetAppRootPath() + "Images/calendar.htc";
InBlock.gif            
//Jxmstc.RootPath mypath = new RootPath();
InBlock.gif
            
InBlock.gif
ExpandedSubBlockEnd.gif        }

InBlock.gif        
protected override void CreateChildControls()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            Controls.Clear();
InBlock.gif            _textBox 
= new TextBox();
InBlock.gif            _textBox.ID 
= "iptCad";
InBlock.gif            _textBox.ReadOnly 
= this.ReadOnly;
InBlock.gif            _textBox.MaxLength 
= this.MaxLength;
InBlock.gif            _textBox.Width 
= this.CssWidth;
InBlock.gif            
if (this.ScriptUrl =="")
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
this.ScriptUrl = GetAppRootPath() +"Images/calendar.htc";
ExpandedSubBlockEnd.gif            }

InBlock.gif            _textBox.Style.Add(
"behavior""url(" + ScriptUrl + ")");
InBlock.gif            
this.Controls.Add(_textBox);
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
protected override void Render(HtmlTextWriter writer)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
InBlock.gif            AddAttributesToRender(writer);
InBlock.gif            _textBox.RenderControl(writer);
InBlock.gif
ExpandedSubBlockEnd.gif        }

InBlock.gif        
//
InBlock.gif        //获取网站根目录
InBlock.gif        
//

InBlock.gif        
//
InBlock.gif
        protected string GetAppRootPath()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
string s = HttpContext.Current.Request.ApplicationPath;
InBlock.gif                
//string s = "";
InBlock.gif
                if (s != "/")
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    s 
+= "/";
ExpandedSubBlockEnd.gif                }

InBlock.gif                
return s;
ExpandedSubBlockEnd.gif            }

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

InBlock.gif 
ExpandedSubBlockEnd.gif        }

InBlock.gif  
InBlock.gif
InBlock.gif
ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

使用的时候,将calendar.htc放入网站根目录的Images中,同时在web.config中添加
None.gif < globalization  requestEncoding ="GB2312"  responseEncoding ="GB2312" />
源码 /Files/longren629/InputCalender.rar

转载于:https://www.cnblogs.com/longren629/archive/2007/01/28/632696.html

你可能感兴趣的:(在网上找到一个js的日期选择控件,然后把它加工成自定义控件了。)