$find to Fetch Extender Behavior

Apr 10, 2008 at 8:21 PM
I can't seem to get a handle on the UpdateProgressOverlay behavior via client-side script.

I need to show the UpdateProgressOverlay when a trigger is fired for an UpdatePanel. I can get the UpdateProgress to show, however the overlay is not the correct size nor in the correct place (it's not overlaying the control).

If I could get a handle on the UpdateProgressOverlay behavior, I could call the _onShow or something to manually show it.
Apr 10, 2008 at 9:25 PM
I figured out a hack to get this to work. It may not be the best way, but it works.

1) In order to get a handle on the UpdateProgressOverlay behavior with javascript I added a property to the ScriptBehaviorDescripter object in the .cs file:

if (string.IsNullOrEmpty(this.BehaviorID)) {
descriptor.AddProperty("id", this.ID);
}
else {
descriptor.AddProperty("id", BehaviorID);
}

2) Once you can get a handle on the behavior object, you need to provide some useful methods, I made a show() and hide() function in the .js file.

show : function() {
this.get_element().style.display = 'block';
this._onShow();
},
hide : function () {
this._onEndRequest();
}


3) Now, in your .aspx page, if you are doing manual showing/hiding of the UpdateProgress control via javascript if using triggers, you can get a handle on the UpdateProgressOverlay Behavior. Make sure you assign a value to the BehaviorID so you can find it via javascript.

function InitializeRequest(sender, args) {
if (prm.get_isInAsyncPostBack()) {
args.set_cancel(true);
}
postBackElement = args.get_postBackElement();
if (postBackElement.id == 'btnUpdatePanel0_Trigger') {
var behavior = $find('myBehaviorID');
behavior.show();
}
}
function EndRequest(sender, args) {
if (postBackElement.id == 'btnUpdatePanel0_Trigger') {
var behavior = $find('myBehaviorID');
behavior.hide();
}
}