using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq; namespace AjaxServerControl1
{
/// <summary>
/// ServerControl1 的摘要说明
/// </summary>
public class ServerControl1 : System.Web.UI.WebControls.Button , IScriptControl
{
public ServerControl1():base()
{
}
public string ClientClickFunction
{
get
{
object value = ViewState["clientClickFunction"];
return (value == null) ? string.Empty : (string)value;
}
set
{
ViewState["clientClickFunction"] = value;
}
}
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
ScriptManager scriptManager = ScriptManager.GetCurrent(Page);
if (scriptManager == null)
{
throw new InvalidOperationException("ScriptManager required on the page.");
}
scriptManager.RegisterScriptControl(this);
}
protected override void Render(HtmlTextWriter writer)
{
base.Render(writer);
if (!DesignMode)
{
ScriptManager.GetCurrent(this.Page).RegisterScriptDescriptors(this);
}
}
public IEnumerable <ScriptDescriptor> GetScriptDescriptors()
{
ScriptControlDescriptor descriptor = new ScriptControlDescriptor("AjaxServerControl1.ClientControl1", this.ClientID);
descriptor.AddEvent("click", ClientClickFunction);
yield return descriptor;
}
// 生成脚本引用
public IEnumerable <ScriptReference> GetScriptReferences()
{
yield return new ScriptReference("AjaxServerControl1.ClientControl1.js", this.GetType().Assembly.FullName);
}
}
}
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq; namespace AjaxServerControl1
{
/// <summary>
/// ServerControl1 的摘要说明
/// </summary>
public class ServerControl1 : System.Web.UI.WebControls.Button , IScriptControl
{
public ServerControl1():base()
{
}
public string ClientClickFunction
{
get
{
object value = ViewState["clientClickFunction"];
return (value == null) ? string.Empty : (string)value;
}
set
{
ViewState["clientClickFunction"] = value;
}
}
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
ScriptManager scriptManager = ScriptManager.GetCurrent(Page);
if (scriptManager == null)
{
throw new InvalidOperationException("ScriptManager required on the page.");
}
scriptManager.RegisterScriptControl(this);
}
protected override void Render(HtmlTextWriter writer)
{
base.Render(writer);
if (!DesignMode)
{
ScriptManager.GetCurrent(this.Page).RegisterScriptDescriptors(this);
}
}
public IEnumerable <ScriptDescriptor> GetScriptDescriptors()
{
ScriptControlDescriptor descriptor = new ScriptControlDescriptor("AjaxServerControl1.ClientControl1", this.ClientID);
descriptor.AddEvent("click", ClientClickFunction);
yield return descriptor;
}
// 生成脚本引用
public IEnumerable <ScriptReference> GetScriptReferences()
{
yield return new ScriptReference("AjaxServerControl1.ClientControl1.js", this.GetType().Assembly.FullName);
}
}
}
Type.registerNamespace("AjaxServerControl1"); AjaxServerControl1.ClientControl1 = function(element) {
this._clickHandler = null;
AjaxServerControl1.ClientControl1.initializeBase(this, [element]);
} AjaxServerControl1.ClientControl1.prototype = {
initialize: function() {
AjaxServerControl1.ClientControl1.callBaseMethod(this, 'initialize');
this._clickHandler = Function.createDelegate(this, this._onClick);
$addHandlers(target, {'click': this._clickHandler}, this);
// 在此处添加自定义初始化
},
dispose: function() {
//在此处添加自定义释放操作
delete this._clickHandler;
AjaxServerControl1.ClientControl1.callBaseMethod(this, 'dispose');
},
add_click : function(handler) {
this.get_events().addHandler('click', handler);
},
remove_click : function(handler) {
this.get_events().removeHandler('click', handler);
},
_onClick : function(e) {
e.preventDefault();
var handler = this.get_events().getHandler('click');
if (handler != null) {
handler(this, Sys.EventArgs.Empty);
}
}
}
AjaxServerControl1.ClientControl1.registerClass('AjaxServerControl1.ClientControl1', Sys.UI.Control); if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();