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

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


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

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

            
set
            
{
                EnsureChildControls();
                _textBox.Text 
= value;
            }

        }


        [
        Bindable(
true), Category("Appearance"), DefaultValue(""), Description("长度")
        ]
        
public int CssWidth
        
{
            
get return (ViewState["Length"!= null ? (int)ViewState["Length"] : 100); }
            
set { ViewState["Length"= value; }        
        }

        [
        Bindable(
true), Category("Appearance"), DefaultValue(""), Description("最大输入长度")
        ]
        
public int MaxLength
        
{
            
get return (ViewState["MaxLength"!= null ? (int)ViewState["MaxLength"] :10); }
            
set { ViewState["MaxLength"= value; }    
        }

        [
        Bindable(
true), Category("Appearance"), DefaultValue(""), Description("是否只读")
       ]
        
public bool ReadOnly
        
{
            
get return (ViewState["ReadOnly"!= null ? (bool)ViewState["ReadOnly"] : false); }
            
set { ViewState["ReadOnly"= value; }        
        }

        [
        Bindable(
true), Category("Appearance"), DefaultValue(""), Description("脚本资源文件地址")
        ]
        
public string ScriptUrl
        
{
            
get return (ViewState["ScriptUrl"!= null ? (string)ViewState["ScriptUrl"] :""); }
            
set { ViewState["ScriptUrl"= value; }    
        }

        
public InputCalender()
        
{
            
//this.ScriptUrl = GetAppRootPath() + "Images/calendar.htc";
            
//Jxmstc.RootPath mypath = new RootPath();
            

        }

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

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


        
protected override void Render(HtmlTextWriter writer)
        
{
            
            AddAttributesToRender(writer);
            _textBox.RenderControl(writer);

        }

        
//<summary>
        
//获取网站根目录
        
//</summary>
        
//<returns></returns>
        protected string GetAppRootPath()
        
{
            
try
            
{
                
string s = HttpContext.Current.Request.ApplicationPath;
                
//string s = "";
                if (s != "/")
                
{
                    s 
+= "/";
                }

                
return s;
            }

            
catch
            
{
                
return "";
            }

 
        }

  


    }

}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值