I'm trying to combine two behaviors into one extender, and I'm having some trouble understanding how exactly to get this done. I've sucessfully created a new extender, which I've named DelayedTextChanged based off one of Garbin's posts here:http://aspadvice.com/blogs/garbin/archive/2006/02/25/15360.aspx
and that works fine, but when I try to create an extender that implements this extender, I'm running into problems.
I'm getting hung up around how exactly to apply the delayedtextchanged behavior to my control(a textbox) using my new extender.
all i really want is this new extender to create the xml script to apply my new behaviors to my controls. something like:
<textBox id="textbox1">
<behaviors>
<atlascontroltoolkit:delayedTextChangedBehavior timeout="500" />
<atlascontroltoolkit:someotherBehavior someOtherProperty="whatever" />
</behaviors>
</textBox
can anyone help me out?
thanks in advance...
jaredHi,
you cannot mix xml-script and extenders in this way because extenders are server controls.
What I suggest is extending the TextBox class to implement the IScriptControl interface. By overriding the RenderScript() method you can inject the desired xml in the Page.
let me first say thank you for your contributions to this community. you are a great help!
but, i'm not sure i understand your explanation. extenders can and do create the xml-script to associate controls with behaviors. the problem is that all of the examples i have seen only associate one behavior with a control. i am trying to understand if it's possible for an extender to associate two or more behaviors in the xml-script...
thanks,
jared
Hi,
jaredmeade:
extenders can and do create the xml-script to associate controls with behaviors
thank you very much. Sorry, looking at your code (too quickly) it seemed to me that you were mixing server controls with xml-script.
jaredmeade:
the problem is that all of the examples i have seen only associate one behavior with a control. i am trying to understand if it's possible for an extender to associate two or more behaviors in the xml-script
I don't want to make wrong assumptions, but I think that the extender model provided by the Atlas Control Toolkit is highly coupled with an (one) "associated" behavior. But again, don't quote me on that. On the other hand, I think that using the general extender model provided by the framework (the ExtenderControl and TargetControlProperties classes found in the Atlas assembly... btw are you using the Control Toolkit extender model?) should do the trick. And finally, it can surely be done by implementing the IScriptControl interface.
Big G,
thanks for the advice. I was able to adapt some of your earlier posts in order to create an extender which overrides RenderScript to produce the xml-script, and it works great!
thanks again,
jared
Actually there is another way to do this, and that's to create a "wrapper" behavior that instantiates and hooks up the other behaviors via code.
So you could have:
Extender1 (C#)/Behavior1(JS)
Extender2 (C#)/Behavior2(JS)
Then you could create a third extender:
[RequiredScript(typeof(Extender1)]
[RequiredScript(typeof(Extender2)]
public class Extender3 { ... }
and in JS:
this.initialize = function() {
// call base
var b1 = new MyNamespace.Behavior1();
var b2 = new MyNamespace.Behavior2();
this.control.get_behaviors().add(b1);
this.control.get_behaviors().add(b2);
b1.initialize();
b2.initialize();
}
Hey Shawn,
That was going to be my second approach if I couldn't figureout how to generate the xml-script.
I'm wondering though, which way is the "recommended" way? Iguess when you think about it, the xml-script is enabling Atlas to create theabove javascript, anyways, right? would creating the javascript like youdemonstrated above be more efficient?
thanks,
jared
Hi Jared -
Well one of the goals of the Toolkit is to prevent the need for people to use XML Script at all.
I took a look at the XML generation code in the ExtenderBase and I didn't see an easy way to get it to generate multiple hookups like that.
Another idea is that you could have one extender create and hookup another.
public class Extender1
void OnLoad() {
Extender2 ext2 = new Extender2();
foreach(TargetProperties tp in TargetProperties) {
Extender2Properties ex2Props = new ();
ex2Props.TargetControlID = tp.TargetControlID;
this.Controls.Add(ext2);
}
}
It depends on how closely releated the behaviors are. If they're always in pair, consider combining them into one. If they're discrete, I'd recommend doing it in Javascript since that's the easiest to maintain and most flexible.
SB
No comments:
Post a Comment