-
MIME Type for .MP4 files is video/mp4
-
I almost made a mistake and put the wrong MIME Type into IIS7 for some MP4 videos that I am serving from a web server. A search for “MP4 mime type” returns two different results:
- video/mp4 (correct)
video/mpeg (not correct)
I was not so sure if there was a difference (although most results did lean toward video/mp4, there were a good number of video/mpeg recommendations out there to make me question the correct one).
To resolve the issue I tried both in IIS7 and Chrome.
For video/mp4 Chrome will give you the HTML5 video player (a very nice user experience):

For video/mpeg Chrome will launch QuickTime... blah!

I didn’t test any other browsers... this was proof enough for me that video/mp4 is the correct MIME type of .MP4 files.
Technorati Tags:
IIS7,
MIME Types,
MP4
-
How to disable an ASP.NET linkbutton when clicked
-
Scenario: User clicks a LinkButton in your ASP.NET page and you want to disable it immediately using javascript so that the user cannot accidentally click it again.
I wrote about disabling a regular submit button here: How to disable an ASP.NET button when clicked. But the method described in the other blog post does not work for disabling a LinkButton. This is because the Post Back Event Reference is called using a snippet of javascript from within the href of the anchor tag:
<a id="MyContrl_MyButton" href="javascript:__doPostBack('MyContrl$MyButton','')">My Button</a>
If you try to add an onclick event to disable the button, even though the button will become disabled, the href will still be allowed to be clicked multiple times (causing duplicate form submissions). To get around this, in addition to disabling the button in the onclick javascript, you can set the href to “#” to prevent it from doing anything on the page. You can add this to the LinkButton from your code behind like this:
MyButton.Attributes.Add("onclick", "this.href='#';this.disabled=true;" + Page.ClientScript.GetPostBackEventReference(MyButton, "").ToString());
This code adds javascript to set the href to “#” and then disable the button in the onclick event of the LinkButton by appending to the Attributes collection of the ASP.NET LinkButton control. Then the Post Back Event Reference for the button is called right after disabling the button. Make sure you add the Post Back Event Reference to the onclick because now that you are changing the anchor href, the button still needs to perform the original postback.
With the code above now the button onclick event will look something like this:
onclick="this.href='#';this.disabled=true;__doPostBack('MyContrl$MyButton','');"
The anchor href is set to “#”, the linkbutton is disabled, AND then the button post back method is called.
-
Visual Studio Shortcut: Surround With
-
I learned a new Visual Studio keyboard shortcut today that is really awesome; the “Surround With” shortcut.
You can trigger the Surround With context menu by pressing the Ctrl-K, Ctrl-S key combination when on a line of code.
Ctrl-K, Ctrl-S means to hold down the Control key and then press K and then while still holding down the Control key press S.
Here is where this comes in handy:
You type a line of code and then realize you need to put it within an if statement block. So you type “if” and hit tab twice to insert the if statement code snippet. Then you highlight the previous line of code that you typed, and then either drag and drop it into the if-then block or cut and paste it. That is not too bad but it is a lot of extra key clicks and mouse moves.
Now try the same with the Surround With keyboard shortcut. Just highlight that line of code that you just typed and press Ctrl-K, Ctrl-S and choose the if statement code snippet, hit tab, and POW!... you are done! No more code moving/indenting required.
Here is what the Surround With context menu looks like:

Just up or down arrow inside the drop down list to the code snippet that you want to surround your currently selected text with. Did I mention this is AWESOME!
Now it is so simple to surround lines of code with an if-then block or a try-catch-finally block... things that usually took several key clicks and maybe one or two mouse moves.
And this works in both Visual Studio 2008 and Visual Studio 2010 which means it has been around for a long time and I never knew about it.