日曆控件

作者:网络 来源:佚名 更新时间:2008-02-05 09:51:47 点击:
国内最大的酷站演示中心!
1.uccalendar.ascx
<%@ control language="vb" autoeventwireup="false" codebehind="uccalendar.aspx.vb" inherits="webapplication1.uccalendar"%>
<font face="新細明體">
<script language="javascript">
function checkdate(o){
var str=new string;
var strend = new string;
str = o.value;
if (str != "" )
{
if (chkformat(str) == false)
{
o.focus();
}
}
}



function chkformat(datestr)
{

var lthdatestr
lthdatestr= datestr.length ;
var tmpy="";
var tmpm="";
var tmpd="";
//var datestr;
var status;
status=0;

for (i=0;i<lthdatestr;i++){
if (datestr.charat(i)== '/'){
status++;
}
if (status>2){
alert("日期錯誤");
return false;
}
if ((status==0) && (datestr.charat(i)!='/')){
tmpy=tmpy+datestr.charat(i)
}
if ((status==1) && (datestr.charat(i)!='/')){
tmpm=tmpm+datestr.charat(i)
}
if ((status==2) && (datestr.charat(i)!='/')){
tmpd=tmpd+datestr.charat(i)
}
}

year=new string (tmpy);
month=new string (tmpm);
day=new string (tmpd)
//tempdate= new string (year+month+day);
//alert(tempdate);
if ((tmpy.length!=4) || (tmpm.length>2) || (tmpd.length>2))
{
alert("日期錯誤");
// alert("date");
return false;
}
if (!((1<=month) && (12>=month) && (31>=day) && (1<=day)) )
{
alert ("日期錯誤");
return false;
}
if (!((year % 4)==0) && (month==2) && (day==29))
{
alert ("日期錯誤");
return false;
}
if ((month<=7) && ((month % 2)==0) && (day>=31))
{
alert ("日期錯誤");
return false;
}
if ((month>=8) && ((month % 2)==1) && (day>=31))
{
alert ("日期錯誤");
return false;
}
if ((month==2) && (day==30))
{
alert("日期錯誤");
return false;
}

return true;
}

</script>
<div align="center"><asp:textbox id="txtcalendar" onblur="checkdate(this)" runat="server" width="181px"></asp:textbox><asp:button id="btncandelar" runat="server" text="...."></asp:button><asp:calendar id="calendar1" runat="server" width="208px" height="200px" borderwidth="1px" backcolor="white"
forecolor="#003399" font-size="8pt" font-names="verdana" bordercolor="#3366cc" cellpadding="1" showgridlines="true">
<todaydaystyle forecolor="white" backcolor="#99cccc"></todaydaystyle>
<selectorstyle forecolor="#336666" backcolor="#99cccc"></selectorstyle>
<nextprevstyle font-size="8pt" forecolor="#ccccff"></nextprevstyle>
<dayheaderstyle height="1px" forecolor="#336666" backcolor="#99cccc"></dayheaderstyle>
<selecteddaystyle font-bold="true" forecolor="#ccff99" backcolor="#009999"></selecteddaystyle>
<titlestyle font-size="10pt" font-bold="true" height="25px" borderwidth="1px" forecolor="#ccccff"
borderstyle="solid" bordercolor="#3366cc" backcolor="#003399"></titlestyle>
<weekenddaystyle backcolor="#ccccff"></weekenddaystyle>
<othermonthdaystyle forecolor="#999999"></othermonthdaystyle>
</asp:calendar></div>
</font>


2.uccalendar.ascx.vb


public class uccalendar

inherits system.web.ui.usercontrol



#region " web form 設計工具產生的程式碼 "



'此為 web form 設計工具所需的呼叫。

<system.diagnostics.debuggerstepthrough()> private sub initializecomponent()



end sub

protected withevents calendar1 as system.web.ui.webcontrols.calendar

protected withevents txtcalendar as system.web.ui.webcontrols.textbox

||| 注册会员,创建你的web开发资料库,

protected withevents btncandelar as system.web.ui.webcontrols.button



'注意: 下列預留位置宣告是 web form 設計工具需要的項目。

'請勿刪除或移動它。

private designerplaceholderdeclaration as system.object



private sub page_init(byval sender as system.object, byval e as system.eventargs) handles mybase.init

'codegen: 此為 web form 設計工具所需的方法呼叫

'請勿使用程式碼編輯器進行修改。

initializecomponent()

end sub



#end region



public property txtcanendar() as string

get

return me.txtcalendar.text

end get

set(byval value as string)

me.txtcalendar.text = value

end set

end property



private sub page_load(byval sender as system.object, byval e as system.eventargs) handles mybase.load

'在這裡放置使用者程式碼以初始化網頁

end sub



private sub calendar1_selectionchanged(byval sender as system.object, byval e as system.eventargs) handles calendar1.selectionchanged

me.txtcalendar.text = me.calendar1.selecteddate.toshortdatestring

me.calendar1.visible = false

end sub



private sub btncandelar_click(byval sender as system.object, byval e as system.eventargs) handles btncandelar.click

if me.calendar1.visible = true then

me.calendar1.visible = false

else

me.calendar1.visible = true

end if

end sub

end class



3.