I have a control extender that disabled a button when clicked to prevent multiple clicks. It worked well on my test.aspx page but when I moved it over to my big project, I get this error:
"Sys.ArgumentException: Value must not be null for Controls and Behaviors.Parameter name: element"
The page I moved it on contains a MasterPage with a home.aspx, and within that there is a .ascx and in there is where my button + control extender are found. Here is the code..cs:
using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI;
[assembly: System.Web.UI.WebResource("OneClickExtender.OneClick.js","text/javascript")]
namespace OneClickExtender
{
[TargetControlType(typeof(Button))]
[TargetControlType(typeof(ImageButton))]
public class OneClick : ExtenderControl
{
private string _submitScript = null;
protected override IEnumerable<ScriptDescriptor> GetScriptDescriptors(Control targetControl)
{
ScriptBehaviorDescriptor behavior = new ScriptBehaviorDescriptor("OneClickExtender.OneClickBehavior",targetControl.ID);
behavior.AddProperty("submitScript", _submitScript);
yield return behavior;
}
protected override IEnumerable<ScriptReference> GetScriptReferences()
{
ScriptReference sr = new ScriptReference();
sr.Name = "OneClickExtender.OneClick.js";
sr.Assembly = "OneClickExtender";
yield return sr;
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
Control target = new Control();
target = FindControl(this.TargetControlID);
if (target != null)
_submitScript = Page.ClientScript.GetPostBackEventReference(target, string.Empty);
}
}
}
.js:
Type.registerNamespace('OneClickExtender');
OneClickExtender.OneClickBehavior = function(element) {
OneClickExtender.OneClickBehavior.initializeBase(this, [element]);
var _clickDelegate = null;
var _onSubmitScript = null;
}
OneClickExtender.OneClickBehavior.prototype = {
initialize : function() {
OneClickExtender.OneClickBehavior.callBaseMethod(this, 'initialize');
var e = this.get_element();
this._clickDelegate = Function.createDelegate(this,this._onClickDelegate);
$addHandler(e,"click",this._clickDelegate);
},
_onClickDelegate : function() {
this.get_element().disabled = true;
eval(this._onSubmitScript);
},
get_submitScript : function() {
return this._onSubmitScript;
},
set_submitScript : function(value) {
this._onSubmitScript = value;
},
dispose: function() {
$clearHandlers(this.get_element ());
OneClickExtender.OneClickBehavior.callBaseMethod(this, "dispose");
}
}
OneClickExtender.OneClickBehavior.registerClass("OneClickExtender.OneClickBehavior", Sys.UI.Behavior);
--
Any ideas?
hello.
instead of using targetcontrol.id i think that you should use targetcontrol.clientid.
This fixed it. However, because I am using asp:RequiredFieldValidator, my button gets disabled and never re-enables itself. I would have to make sure all fields were valid first. I will look into this right now.
No comments:
Post a Comment