Showing posts with label files. Show all posts
Showing posts with label files. Show all posts

Wednesday, March 28, 2012

Extender with inclusion of JS files in particular order.

Right now I'm working on an extender that needs to include numerous .js files I'd like to register for inclusion on a page.

I've added:

[assembly: System.Web.UI.

WebResource("first.js","text/javascript")]

[assembly: System.Web.UI.

WebResource("second.js","text/javascript")]

In the root of the Extender.cs class... as well as...

[ClientScriptResource("first","first.js")]

[

ClientScriptResource("second","second.js")]

Seems like if it were just one of the scripts by itslef it seems to do an ok job... but for scrips that rely on eachother, the straight up fail. Is the extender model only destined to have one script file period? If not, are scripts loaded and rendered in the order I add the ClientScriptResource attributes?

Is there another way I SHOULD be doing this? The .js files are being bundled in as Embedded Resource which is desired functionality, however the js variables that are now supposed to be present at the document scope simply arent. Somethign strange about which scripts are being loaded, or what order they are being loaded in.

Any advice would be greatly appreciated. Thanks

ClientScriptResource also takes named parameters, of which there is a LoadOrder and you can specify a load order. I found this to be the solution to my problem. Couple small little hurdles and I should be on my way.

Wednesday, March 21, 2012

Events are firing at the wrong time, I dont know how to stop them

Hi,

Here are the files for a very simple project containing some user controls.

http://www.wmscanner.com/Happiness.zip

If you open the fileUserControls/StrikeDistance.ascx.cs you will be able to quickly see three event handlers that I have marked with comments.

My problem is that these event handlers are being fired on every single postback even when I don't want them to fire.

The controls contain an AJAX SliderExtension, and I want the event handlers to fire ONLY after a user has adjusted one of the sliders. Instead, the events are firing willy nilly, especially on the first couple of postbacks.

I have made the attached project very simple, to isolate the problem, so it should be pretty easy for someone expert in control lifecycles to step through and see where my code is "improveable" :)

Many, many thanks in advance, i've been working on this one problem an entire day now :)

Ben

OK, I found the problem and it was my fault. I was setting the sliderextender's value to 0.1 when it's "Decimals" property was set to zero. The slider extender was resetting the text of its bound control, and that was firing the unwanted events.