Forum » Programiranje » Custom AJAX extender control - klicanje s codebehind
Custom AJAX extender control - klicanje s codebehind
Seth ::
Naredil sem custom ajax extender, ki ga pripnem na gumb (server control). Spodnji primer je trivialen, ampak gumb na katerem definiram ta extender zažene alert('OK') v spodnji JS datoteki, kar deluje po pričakovanjih. Zanima me kako pognati ta isti "alert" preko codebehind. V .cs datoteki imam metodo CallMethod(), ki bi po mojem razumevanju nekako morala poklicati funkcijo v .js.
Hvala za kakršno koli idejo!
extendercontrol.cs
in ClientBehavior1.js
Hvala za kakršno koli idejo!
extendercontrol.cs
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 AExtender { [ TargetControlType(typeof(Button)) ] public class ExtenderControl1 : ExtenderControl { protected override IEnumerable<ScriptDescriptor> GetScriptDescriptors(System.Web.UI.Control targetControl) { ScriptBehaviorDescriptor descriptor = new ScriptBehaviorDescriptor("AExtender.ClientBehavior1", targetControl.ClientID); yield return descriptor; } // Generate the script reference protected override IEnumerable<ScriptReference> GetScriptReferences() { yield return new ScriptReference("AExtender.ClientBehavior1.js", this.GetType().Assembly.FullName); } protected void CallMethod() { // Del kjer naj bi extender pognal preko codebehind z enakim efekotom kot z gumbom } } }
in ClientBehavior1.js
Type.registerNamespace("AExtender"); AExtender.ClientBehavior1 = function(element) { AExtender.ClientBehavior1.initializeBase(this, [element]); var _clickDelegate = null; } AExtender.ClientBehavior1.prototype = { initialize: function () { AExtender.ClientBehavior1.callBaseMethod(this, 'initialize'); var e = this.get_element(); e.onclick = function () { return false }; this._clickDelegate = Function.createDelegate(this, this._onClickDelegate); $addHandler(e, "click", this._clickDelegate); }, _onClickDelegate: function (sender, ea) { alert('OK'); }, dispose: function () { AExtender.ClientBehavior1.callBaseMethod(this, 'dispose'); } } AExtender.ClientBehavior1.registerClass('AExtender.ClientBehavior1', Sys.UI.Behavior); if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();
Seth
Vredno ogleda ...
Tema | Ogledi | Zadnje sporočilo | |
---|---|---|---|
Tema | Ogledi | Zadnje sporočilo | |
» | ASP.NET + C# vprašanjeOddelek: Programiranje | 2799 (1813) | Morenov |
» | ASPX preusmeritvena zankaOddelek: Programiranje | 2126 (2031) | Senzacionale |
» | [c#]4 v vrsto - padanje krogovOddelek: Programiranje | 1998 (1830) | VASkO |
» | [ ASP.NET ] Vprašanje glede podajanja parametrovOddelek: Programiranje | 1577 (1308) | salesky |
» | [.NET ASP] Napaka : Specified cast is not validOddelek: Programiranje | 1132 (1085) | pinc |