, , jQuery ? , IScriptControl.
, :
Project
|...Controls
|...MyDateTimePicker.cs
|...MyDateTimePicker.js
MyDateTimePicker.js , :
[assembly: System.Web.UI.WebResource("Project.Controls.MyDateTimePicker.js", "text/javascript")]
, MyDateTimePicker.cs :
[DefaultProperty("ID")]
[ToolboxData("<{0}:MyDateTimePicker runat=server />")]
public class MyDateTimePicker : WebControl, IScriptControl
{
}
, ScriptControl, :
protected override void OnPreRender(EventArgs e)
{
if (!this.DesignMode)
{
ScriptManager scriptManager = ScriptManager.GetCurrent(this.Page);
if (scriptManager != null)
{
scriptManager.RegisterScriptControl(this);
scriptManager.RegisterScriptDescriptors(this);
scriptManager.Scripts.Add(new ScriptReference(
"Project.Controls.MyDateTimePicker.js", "Project"));
}
else
{
throw new ApplicationException("You must have a ScriptManager on the Page.");
}
}
base.OnPreRender(e);
}
, . , , ..
public virtual string TimeHourFormat {get;set;}
public virtual string TimeFormat {get;set;}
, script:
IEnumerable<ScriptDescriptor> IScriptControl.GetScriptDescriptors()
{
ScriptControlDescriptor desc = new ScriptControlDescriptor("Project.MyDateTimePicker",
this.ClientID);
desc.AddProperty("timeHourFormat", this.TimeHourFormat);
desc.AddProperty("timeFormat", this.TimeFormat);
yield return desc;
}
IEnumerable<ScriptReference> IScriptControl.GetScriptReferences()
{
ScriptReference reference = new ScriptReference();
reference.Assembly = Assembly.GetAssembly(typeof(MyDateTimePicker)).FullName;
reference.Name = "Project.MyDateTimePicker.js";
yield return reference;
}
script, jQuery. MyDateTimePicker.js !
Type.registerNamespace('Project');
Project.MyDateTimePicker = function (element) {
this._timeHourFormat = null;
this._timeFormat = null;
Project.MyDateTimePicker.initializeBase(this, [element]);
}
Project.MyDateTimePicker.prototype =
{
initialize: function () {
Project.MyDateTimePicker.callBaseMethod(this, 'initialize');
$(document).ready(
);
},
dispose: function () {
Project.MyDateTimePicker.callBaseMethod(this, 'dispose');
},
doSomething: function (e) {
},
get_timeHourFormat: function () {
return this._timeHourFormat;
},
set_timeHourFormat: function (value) {
var e = Function._validateParams(arguments, [{ name: 'value', type: String}]);
if (e) throw e;
if (this._timeHourFormat != value) {
this._timeHourFormat = value;
this.raisePropertyChanged('timeHourFormat');
}
},
get_timeFormat: function () {
return this._timeFormat;
},
set_timeFormat: function (value) {
var e = Function._validateParams(arguments, [{ name: 'value', type: String}]);
if (e) throw e;
if (this._timeFormat != value) {
this._timeFormat = value;
this.raisePropertyChanged('timeFormat');
}
}
}
Project.MyDateTimePicker.registerClass('Project.MyDateTimePicker', Sys.UI.Control);
if (typeof(Sys) != 'undefined')
{
Sys.Application.notifyScriptLoaded();
}