(转)一个基于JS日历的WebControl日历控件
源代码如下:
using System;
using System.Web.UI.WebControls;
using System.Web;
using System.Web.UI;
using System.ComponentModel;

namespace PeoNormalControl
{
//// <summary>
/// JS类型的DateTimePicker
/// </summary>
[
ParseChildren(false)
]
[
ToolboxData("<{0}:DateTimePicker runat=server></{0}:DateTimePicker>"),DefaultEvent
("DateChanged"),ValidationProperty("DateText"),
]
public class DateTimePicker:WebControl,IPostBackDataHandler
{
public DateTimePicker()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
private static object EventDateChangedObject;
//public event EventHandler DateChanged;

数据成员

设置属性

事件

重写方法
}
internal sealed class Util
{
private Util()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
internal static String ResolveClientUrlSimple(string relativeUrl)
{

if (relativeUrl == null)
{
throw new ArgumentNullException("relativeUrl");
}
if (relativeUrl.Length == 0) return relativeUrl;
if (relativeUrl.StartsWith("~"))
{
string text1 = HttpContext.Current.Request.ApplicationPath;
if (text1.Length == 0)
{
return relativeUrl;
}
return text1+relativeUrl.TrimStart('~');
}
return relativeUrl;
}
internal static string GetClientValidatedPostback(Control control)
{
string text1 = control.Page.GetPostBackEventReference(control);
return ("{if (typeof(Page_ClientValidate) != 'function' || Page_ClientValidate()) " + text1 + "} ");
}
internal static void RegisterGlobalClientScript(string sDefaultPath, string sScriptFile,Page oPage)
{
string sInstanceId = sScriptFile;
if(oPage.IsClientScriptBlockRegistered(sInstanceId)) return;
string sScript = string.Empty;
sDefaultPath = ResolveClientUrlSimple(sDefaultPath);
try
{
string sStandardRootClientScriptPath = Path.Combine(sDefaultPath, sScriptFile).Replace("\\", "/");

if(File.Exists(HttpContext.Current.Server.MapPath(sStandardRootClientScriptPath)))
{
sScript = "<script language=\"javascript\" src=\"" + sStandardRootClientScriptPath + "\" type=\"text/javascript\"></script>";
}
}
catch {}
if(sScript == string.Empty)
{
try
{
string sAppRootClientScriptPath = Path.Combine(Path.Combine(HttpContext.Current.Request.ApplicationPath, "js"), sScriptFile).Replace("\\", "/");

if(File.Exists(HttpContext.Current.Server.MapPath(sAppRootClientScriptPath)))
{
sScript = "<script language=\"javascript\" src=\"" + sAppRootClientScriptPath + "\" type=\"text/javascript\"></script>";
}
}
catch {}
}
// If everything failed, emit our internal script
if(sScript == string.Empty)
{
sScript = DemarcateClientScript(GetResourceContent(Assembly.GetExecutingAssembly().GetName().Name + "." + sScriptFile));
}

oPage.RegisterClientScriptBlock(sInstanceId, sScript);
}
internal static string GetResourceContent(string sFileName)
{
Stream oStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(sFileName);
if (oStream == null) throw new FileNotFoundException("内嵌资源未找到。",sFileName);
StreamReader oReader = new StreamReader(oStream);
return oReader.ReadToEnd();
}
internal static string DemarcateClientScript(string script)
{
return DemarcateClientScript(script, null);
}
internal static string DemarcateClientScript(string script, string title)
{
StringBuilder result = new StringBuilder();
result.Append("<script language=\"javascript\" type=\"text/javascript\">\n");
result.Append("//<![CDATA[\n");
if (title != null)
{
result.Append("* "); result.Append(title); result.Append(" ***/\n");
}
result.Append(script);
result.Append("\n");
result.Append("//]]>\n");
result.Append("</script>\n");
return result.ToString();
}
}
}
用到的JS日历为梅花日历,文件的下载地址为:http://briefcase.tom.com/download.php?fileID=1403989
using System;
using System.Web.UI.WebControls;
using System.Web;
using System.Web.UI;
using System.ComponentModel;
namespace PeoNormalControl
{
//// <summary>
/// JS类型的DateTimePicker
/// </summary>
[
ParseChildren(false)
]
[
ToolboxData("<{0}:DateTimePicker runat=server></{0}:DateTimePicker>"),DefaultEvent
("DateChanged"),ValidationProperty("DateText"),
]
public class DateTimePicker:WebControl,IPostBackDataHandler
{
public DateTimePicker()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
private static object EventDateChangedObject;
//public event EventHandler DateChanged;
数据成员
设置属性
事件
重写方法
}
internal sealed class Util
{
private Util()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
internal static String ResolveClientUrlSimple(string relativeUrl)
{
if (relativeUrl == null)
{
throw new ArgumentNullException("relativeUrl");
}
if (relativeUrl.Length == 0) return relativeUrl;
if (relativeUrl.StartsWith("~"))
{
string text1 = HttpContext.Current.Request.ApplicationPath;
if (text1.Length == 0)
{
return relativeUrl;
}
return text1+relativeUrl.TrimStart('~');
}
return relativeUrl;
}
internal static string GetClientValidatedPostback(Control control)
{
string text1 = control.Page.GetPostBackEventReference(control);
return ("{if (typeof(Page_ClientValidate) != 'function' || Page_ClientValidate()) " + text1 + "} ");
}
internal static void RegisterGlobalClientScript(string sDefaultPath, string sScriptFile,Page oPage)
{
string sInstanceId = sScriptFile;
if(oPage.IsClientScriptBlockRegistered(sInstanceId)) return;
string sScript = string.Empty;
sDefaultPath = ResolveClientUrlSimple(sDefaultPath);
try
{
string sStandardRootClientScriptPath = Path.Combine(sDefaultPath, sScriptFile).Replace("\\", "/");
if(File.Exists(HttpContext.Current.Server.MapPath(sStandardRootClientScriptPath)))
{
sScript = "<script language=\"javascript\" src=\"" + sStandardRootClientScriptPath + "\" type=\"text/javascript\"></script>";
}
}
catch {}
if(sScript == string.Empty)
{
try
{
string sAppRootClientScriptPath = Path.Combine(Path.Combine(HttpContext.Current.Request.ApplicationPath, "js"), sScriptFile).Replace("\\", "/");
if(File.Exists(HttpContext.Current.Server.MapPath(sAppRootClientScriptPath)))
{
sScript = "<script language=\"javascript\" src=\"" + sAppRootClientScriptPath + "\" type=\"text/javascript\"></script>";
}
}
catch {}
}
// If everything failed, emit our internal script
if(sScript == string.Empty)
{
sScript = DemarcateClientScript(GetResourceContent(Assembly.GetExecutingAssembly().GetName().Name + "." + sScriptFile));
}

oPage.RegisterClientScriptBlock(sInstanceId, sScript);
}
internal static string GetResourceContent(string sFileName)
{
Stream oStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(sFileName);
if (oStream == null) throw new FileNotFoundException("内嵌资源未找到。",sFileName);
StreamReader oReader = new StreamReader(oStream);
return oReader.ReadToEnd();
}
internal static string DemarcateClientScript(string script)
{
return DemarcateClientScript(script, null);
}
internal static string DemarcateClientScript(string script, string title)
{
StringBuilder result = new StringBuilder();
result.Append("<script language=\"javascript\" type=\"text/javascript\">\n");
result.Append("//<![CDATA[\n");
if (title != null)
{
result.Append("* "); result.Append(title); result.Append(" ***/\n");
}
result.Append(script);
result.Append("\n");
result.Append("//]]>\n");
result.Append("</script>\n");
return result.ToString();
}
}
}用到的JS日历为梅花日历,文件的下载地址为:http://briefcase.tom.com/download.php?fileID=1403989


浙公网安备 33010602011771号