In a previous post I was writing about a fix to remove the Press Spacebar or Enter to activate or use this control message. But it also made a mess out of a flash file I was trying to use. After a lot of looking into the source code (Flex) and trying to understand what happened, I found a solution.

First of all, you will find a lot of web pages advocating using a parameter called flashVars for sending parameters to Flash applications. Then you would use Application.application.parameters to get the variables URLEncoded in flashVars. That works in most cases, but not when:
a. you used an IE fix for the annoying message
b. you have in the movie and/or src parameters an url that has parameters. (like when you would get the SWF file out from an HttpHandler, for example)

The solution is to put all the variables you would put in the flashVars in the url of the movie or src parameters.

So, instead of :
<param name='movie' value='test.swf' />
<param name='flashVars' value='a=%27test%27&b=12' />

use
<param name='movie' value='test.swf?a=%27test%27&b=12' />

Don't forget to UrlEncode the values.

But why does this happen? Apparently, the problem is that after setting the innerHTML property the FlashVars param element has an empty value. I tried to fix the javascript to 1. get the value of FlashVars 2. do the fix 3. replace the empty FlashVars value with the saved value. It did not work! Even by javascript, after finding the param element with the name of FlashVars and an empty value, I could not set the value of the element. It probably has to do with the IE "fix". Something must clear the FlashVars when being set from anything else but from source.

Ok, the why is something I could never truly understand. It's some lawyer thing. But the fact remains that Microsoft was legally bound to show that message on each ActiveX control in Internet Explorer, thus screwing everybody and all their Flash pages.

When you Google this you find a miriad solutions. Some of them rewrite the entire HTML, others just take all the objects and embeds and rewrite their innerHTML or their outerHtml. But sometimes, it just seems that none of them work. And here is the catch for all of them: in order to work, the function that does the replacing of the HTML must be in an external Javascript file. Yes, you read right, if the function is inside the page, it doesn't work. Weird, huh?

Anyway, here is the script I use. It works, apparently.

function fixFlash() {
//ediy v2
n=navigator.userAgent;
w=n.indexOf("MSIE");
if((w>0)&&(parseInt(n.charAt(w+5))>5)){
T=["object","embed","applet"];
for(j=0;j<2;j++){
E=document.getElementsByTagName(T[j]);
for(i=0;i<E.length;i++){
P=E[i].parentNode;
H=P.innerHTML;
P.removeChild(E[i]);
P.innerHTML=H;
}}}
}


For more information about other solutions and the legal issue between Microsoft and Eolas read this specialised blog: IE ActiveX Change "Click to activate and use this control"

Update:
Well, I noticed that the Flash file I wanted to use stopped working after using this fix. Luckily I had the source and so I found a fix. The next post details it.

It all started with my own library, a dll in which I wanted to include Javascript, CSS and ultimately images or flash files. I did it the only way I could in 1.1, mainly adding the resources to the project, setting them as Embedded Resource, then reading them and either put them in the page or write them in the application directory and link them in the page. As you can imagine, there were a lot of issues related to writing writes and so on.

But then .NET 2.0 and the AjaxControlToolkit arrived. This toolkit had this funny looking Tab thing, and it used images. So where did it get the images? I was surprised to see that the namespace of the TabContainer control was decorated with stuff like this:

[assembly: WebResource("AjaxControlToolkit.Tabs.tab.gif", "image/gif")]

then in the CSS files, stuff like

background-image:url(<%=WebResource("AjaxControlToolkit.Tabs.tab.gif")%>)

Could it be so easy? yes! And for the js files, they had this class called a ScriptControlBase and the only thing you needed to do to insert a javascript file was decorate the implementing class like this:

[ClientScriptResource("AjaxControlToolkit.TabPanel", "AjaxControlToolkit.Tabs.Tabs.js")]

But what was the underlying mechanism? Googling for WebResource.axd you get these informative links:
Using WebResource.axd for embedded resources
Accessing Embedded Resources through a URL using WebResource.axd

Working with Web Resources in ASP.NET 2.0

These three articles pretty much explain the basics, so I won't do anything but emphasize the more important points:
  • When you use the name of the resource, either when decorating the namespace or when getting the reference to it, use the project namespace and the folder in which the file is in, otherwise it will not work. So if you have the namespace MyControls.Web and you have the folder Images in which you embedded an Image.gif file, the name should be MyControls.Web.Images.Image.gif.
  • To programatically get the url for an embedded resource use Page.ClientScript.GetWebResourceUrl(Type type,string resourceName)
  • In order to get the contents of an embedded resource use code like this:
    Assembly assembly = GetType().Assembly;
    arr = assembly.GetManifestResourceNames();
    foreach (string name in arr)
    if (name==resourceName) {
    Stream s = assembly.GetManifestResourceStream(name);
    // do something with the stream
    break;
    }


But what is this WebResource.axd? It's an IHttpHandler, one that you can also implement quite easily. They are used to handle Ajax, file uploads, get access to all kinds of resources. Look it up. Somewhere in the near future I might write an article about these, too.

and has 0 comments
It happened to everyone: you opened a bunch of sites and you have to go or restart your computer or something like that. You would like to save those tabs for later reference. Well, Internet Explorer does have something built in to take care of this, but it's kind of stupid. A third party software would be far better.

But anyway, you are in a hurry, you want a quick solution and I have two for you:
1. Make sure you have set Warn me when closing multiple tags in Internet Options, then close your browser. It will ask you if you want to close all tabs, click on Show Options, check Open these next time I use Internet Explorer.

2. Go to Internet Options and then just click Use current in the Home page section. It will set all your open sites as home pages.

In Firefox things are far better. Just right click on the tabs bar and bookmark all. It will ask you to save them with a name. Then just go to the Bookmarks menu and reload them.

and has 0 comments

I remembered today of a song that I liked to listen to called Everything for Free, by K's Choice. Back then (oh, my tired bones) the Internet was not yet as... evolved as these days and you couldn't really get all the discography of an artist in a few minutes, so I only listened to this one song that was also on MTV.

I am putting the video clip here, but really do look into the singer, Sarah Bettens, who also has a solo project beyond K's Choice and has a lot of videos on YouTube. Here are some sites you can visit:

K's ChoiceSarah Bettens
Official SiteXX
Myspace SiteXX
Wikipedia SiteXX

[youtube:AxY6KrqGnCw]

Update: in IE7 I noticed that the style property doesn't keep the inherited values or the CSS values, but only the inline values of style. 'currentStyle' keeps all values, therefore I used that too, in case style would not work.

Update: the same can be done in FireFox by using the document.defaultView.getComputedStyle(myObject, null) syntax equivalent to myObject.currentStyle in Internet Explorer. I have not updated my function to work with that, though.

Update: By adding a break in case of relative or absolute positioning I seemed to have fixed most of the issues regarding those types of positioned elements.

Whenever one wants to popup something with Javascript, the bigger problem arising is to find the absolute position of the element that you want the popup to cling to. Searching the web you will probably find a site like this: How to get an element’s position and area, you will try that solution and say "Wee! It works!" until you scroll something inside the page and everything turns to mush.

Analysing the code and the html you will see that it ignores completely the scrolling of various elements. Even worse, the offsetParent is one for Internet Explorer and another for FireFox. So here is my solution, which seems to work in most cases. I will work on it some more, but not in the near future and usually one doesn't need a popup in a popup. So here is the code:

function findPos(obj)
{
var curleft = 0;
var curtop = 0;
if (obj.offsetParent)
{
while (obj.offsetParent)
{
curleft += obj.offsetLeft-obj.scrollLeft;
curtop += obj.offsetTop-obj.scrollTop;
var position='';
if (obj.style&&obj.style.position)
position=obj.style.position.toLowerCase();
if (!position)
if (obj.currentStyle && obj.currentStyle.position)
position = obj.currentStyle.position.toLowerCase();
if ((position=='absolute')||(position=='relative')) break;
while (obj.parentNode!=obj.offsetParent) {
obj=obj.parentNode;
curleft -= obj.scrollLeft;
curtop -= obj.scrollTop;
}
obj = obj.offsetParent;
}
}
else {
if (obj.x)
curleft += obj.x;
if (obj.y)
curtop += obj.y;
}
return {left:curleft,top:curtop};
}

and has 0 comments
This song is one of my latest favourites, even if the sound itself is a bit too much like country music, the lyrics are really funny. I wasn't able to find the video for the song, so here is a random video one.



Poe, by her real name Ann Danielewski is the daughter of the Polish director Tad Danielewski and is singing since 1990. Look for her other songs as well, some are really smart and they sound pretty cool.

I was minding my own business, making user controls in a big project we've been working for the last year and I've stumbled upon the "circular file references are not allowed." error. It was annoying not only because I haven't met before and I was certain there was no circular reference, but also because sometimes it compiled the whole site without any errors, only to fail the next build with the same error.

Google saved me when I found this discussion: http://forums.asp.net/t/922622.aspx. It might be a little long to read and understand so here is the short version:

ASP.Net 2.0 compiles sites by creating a DLL for each folder. Therefore if you have references that are not circular in pages, controls or classes, they can be circular in these DLLs. You have two solutions:

Solution A is to use batch="false" in the compilation tag of the web.config file. This is not really a solution as it forces ASP.Net to compile a DLL for each page and control. It might work, but it slows compilation terribly and it is also not suitable for production builds, only for development.

Solution B is to move all referenced controls in a single directory. In my case there was a Controls directory and one of the controls was outside, referenced both in a control in Controls and in a page in the base directory. Moving my user control to the Controls folder solved the problem!

Bottom line: try to avoid referencing across folders.

Yesterday I was trying to make one of my controls keep its scroll position. Since you can't set a scrollTop attribute (which I think it is dumb, but that's another issue) I used a HiddenField and some Javascript. Mainly one at submit that loaded the scrollTop value in the hidden field and one on load to re-set it.

Since the logic of my control was mainly in the Render method of the control, I wrote the RegisterStartupScriptBlock and RegisterOnSubmitStatement lines there. It worked like a charm, but then I decided to see if it works WITHOUT Ajax.Net by removing the update panel I have been using. It failed!

I wasted like two hours before I understood that the RegisterOnSubmitStatement did not add anything to the page. I moved it in the OnPreRender method of the control and it worked!

So, long story short: DO NOT use RegisterOnSubmitStatement in the Render method of controls, as I believe the onsubmit (and possibly ClientScriptBlocks) are rendered by the page before any of the controls on it.

Someone else talks about it here.

and has 1 comment
How to Sleep Better is a BBC programme that tries to solve some of the issues related to sleep. It does NOT show you how to sleep better in a shorter time, it is about fixing the problems that make you sleep badly or less than you want.

The program is very interesting indeed. I was kind of put off when I didn't find it on video.google.com and it is not found freely on the programme's site either, so you should seek it on BitTorrent or DC++.

Anyway, long story ridiculously short, it started from a survey of common sleep problems and then they tried to find solutions. There was a snorer, a couple with a screaming child, a woman too obsessed by work to sleep well, an old man who couldn't sleep well from his youth, a flight attendant that could not sleep well in her own home, but could do it in a hotel and some guy that worked driving night shifts.

Solutions:

The snorer should lose weight to relieve some of the fat on her neck, but she could also try tennis balls hooked on her back (with a bra) to stop her from sleeping on her back. But there was a thing that she put in her mouth that solved it. Apparently, snoring is treatable in 99% of the cases.

The couple with the screaming child should not have had so many children in the first place and they could also have aborted, killed or at least seriously beat them to make the kid shut up. But what they actually did was to first analyse the problem, which was that the child associated sleep with the presence of his parents close by, and then solve it by slowly going further away from the child each night when put to sleep. Eventually the brat learned to sleep by himself and not feel frightened when alone in bed.

The woman that was obsessive about her work and other problems solved it by scheduling her activities each day and sticking to the schedule and also writing down any problem that obsessed her. It seems, at least in her case, to ease the need for her brain to ceaselessly remember and analyse the problem if it was written down.

The old man was so worked up about not being able to sleep that he actually kept himself awake by worrying that he won't be able to sleep. They solved it by forcing him to try to stay awake :)

The flight attendant has a clogged bedroom. Her room looked more like a prison cell than a sanctuary (that's more or less their words) and when they rearranged her room (basically by drawing a line in it and separating a third of the room for storage and the other two thirds for relaxation). That helped her ease up and feel comfortable in her own apartment.

The night shift guy "cheated". He quit his job! :)

There was also interesting information about the drinks that keep us awake (like coffee, tea, fizz drinks) and foods (apparently aged foods like salamis and a bit potatoes) and about how some people are night people and some are day people. Trying to wake and go to sleep early would work wonders on some and terrible on others.

Try to find it, even if the presenter, Robert Winston, is a bit silly looking. He is a smart man even if he does look like one of the Marx Brothers :)

and has 0 comments
Yes! A message for women everywhere :) Garbage has better songs, but this one is with dedication ;)

and has 0 comments
New video from Foo Fighters. In case you are wondering why I am posting music videos in my blog, it's so that I can click on the little 'music' label and listen to whatever music I like, wherever I am. So if you want to see all music posted by me, use the labels!

and has 0 comments
Many a solution on the net propose clearing a html page of images, dropdowns, buttons, checkboxes, radiosbuttons, etc and replacing them with text, then outputing the result as an Excel file. Excel is smart enough to understand the simplest HTML and opens the html as an Excel. The user only has to save the file as an XLS and everything is set.

But what about styles? Apparently, Excel does not work with numerically defined colors, but instead it uses a predefined set of 40 colors and displays any numerically defined color as the closest of these 40. It is a drag to see a beautiful page rendered in Excel in only the coarsest of colors.

But, if you are trying to build an "Excel compatible" page, or if you want to use a separate style for the excel export (btw, Excel doesn't understand stylesheets, so you have to save all style in a <STYLE> tag and NOT use multiple class names in the same class property like "class1 class2". Older Excels might not even do that) then you have to use the colors that Excel uses. Here is a list, as taken from my Office 2003:
        
Black
Negru
Maroon
Maro
Dark Olive
Oliv inchis
Dark Green
Verde inchis
Dark Blue
Albastru inchis
Navy Blue
Bleumarin
Indigo80% Gray
Gri-80%
#000000#993300#333300#003300#000040#000080#333399#333333
        
Gold Red
Bordo
Orange
Portocaliu
Olive Green
Verde Oliv
Green
Verde
Teal Blue
Albastru Verzui
Blue
Albastru
Gray Blue
Gri albastrui
50% Gray
Gri-50%
#800000#FF6600#808000#008000#008080#0000FF#666699#808080
        
Red
Rosu
Yellow Orange
Galben Portocaliu
Yellow Green
Verde galbui
Sea Green
Verde marin
CyanLight Blue
Albastru deschis
Violet
Violet
40% Gray
Gri-40%
#FF0000#FF9900#99CC00#339966#33CCCC#3366FF#800080#969696
        
Fuchsia
Ciclam
Gold
Auriu
Yellow
Galben
Lime
Verde aprins
Aqua
Turcoaz
Sky Blue
Azuriu
Violet Red
Mov
25% Gray
Gri-25%
#FF00FF#FFCC00#FFFF00#00FF00#00FFFF#00CCFF#993366#C0C0C0
        
Pink
Roz
Ocre
Ocru
Light Yellow
Galben pal
Light Green
Verde deschis
Light Aqua
Turcoaz deschis
Light Blue
Bleu pastel
Orchid
Lila
White
Alb
#FF99CC#FFCC99#FFFF99#CCFFCC#CCFFFF#99CCFF#CC99FF#FFFFFF

It's very complicated to change the default culture for SQL Server: SET LANGUAGE 'English'. Duh!

and has 0 comments
Now this is a Russian band with a male+female vocal. This is by far the best of their songs and they have a nice video clip on it. Enjoy!


Official Slot site (Russian): http://slot.ru
MySpace Slot site (English): http://myspace.com/theslot