17. August 2012 10:52
by Henrik Stenbæk
0 Comments
Note to self: This seems to work - even with danish date formats:
$(".datepicker").each(function() {
$(this).datepicker('setDate', $(this).val());
});
http://jsfiddle.net/DDsBP/2/
31. March 2011 01:06
by Henrik Stenbæk
0 Comments
If you have one application on your IIS and several domain names pointing to it, it’s possible to have different robots.txt files served based on the current domain name.
1. Add a route
![CropperCapture[1] CropperCapture[1]](/image.axd?picture=Windows-Live-Writer/Dynamic-robots.txt-with-ASP.NET-MVC/4351DEE1/CropperCapture1_thumb.jpg)
2. Create the RobotsController
![CropperCapture[2] CropperCapture[2]](/image.axd?picture=Windows-Live-Writer/Dynamic-robots.txt-with-ASP.NET-MVC/064DAD4F/CropperCapture2_thumb.jpg)
3. The SeoHelper just implements a simple way of determine what robots.txt file to return
![CropperCapture[3] CropperCapture[3]](/image.axd?picture=Windows-Live-Writer/Dynamic-robots.txt-with-ASP.NET-MVC/52A540F0/CropperCapture3_thumb.jpg)
4. Add the different versions of the robot.txt to the site root – remark the content for the robots.txt could be served from any source, I have just chosen a simple model to keep it simple
![CropperCapture[4] CropperCapture[4]](/image.axd?picture=Windows-Live-Writer/Dynamic-robots.txt-with-ASP.NET-MVC/02EC15A7/CropperCapture4_thumb.jpg)
5. Run the site and request robots.txt
![CropperCapture[5] CropperCapture[5]](/image.axd?picture=Windows-Live-Writer/Dynamic-robots.txt-with-ASP.NET-MVC/3647D903/CropperCapture5_thumb.jpg)
![CropperCapture[6] CropperCapture[6]](/image.axd?picture=Windows-Live-Writer/Dynamic-robots.txt-with-ASP.NET-MVC/2011BDB1/CropperCapture6_thumb.jpg)
Get the source code: DynamicRobotsTxt.rar (21,66 kb)
4. December 2008 23:22
by Henrik Stenbæk
3 Comments
Just for the record
An asp:ImageButton without image won’t fire its events in Firefox
Remember this and save yourself an hour: always attach an image to your asp:ImageButton
28. March 2008 00:32
by Henrik Stenbæk
0 Comments
I just had one of those WOW experience today when I happened to use the switch code snippet with an enum.
I had an enum like this:
1: enum MyEnum
2: { 3: value_1,
4: value_2,
5: value_3,
6: value_4,
7: value_5
8: }
Start the video to se what happened when I tapped out of the snippet "switch_on" field.
WOW the snippet automatically created:
case MyEnum.value_1:
break;
for each element in the enum. But how did it do that? Looking into the switch.snippet file I found:
<Literal Editable="false">
<ID>cases</ID>
<Function>GenerateSwitchCases($expression$)</Function>
<Default>default:</Default>
</Literal>
It's the GenerateSwitchCases function that's doing the job - one out of 3 pre defined functions that available to "snippets"
19. March 2008 00:56
by Henrik Stenbæk
1 Comments
I don’t know about you but I for my part often end out writing linear code.
Maybe it’s a hangover from writing to much BASIC code in the mid 80’s or maybe it’s just me thinking linear and not that much object-oriented. After all I often end up with “long functions” that includes code that could be isolated in “sub functions”.
Today one of my colleges pointed out the Refactor->Extract Method function. This function takes a part of your code and isolate it’s in a separate function.
Look at the code in this Page_Load: its includes some silly greeting stuff (just for the demo), the function is long and hard to read, lets try to separate the greetings part in a separate function.
Highlight the code you want to move to a new function, right click and select Refactor -> Extract Metod.
Give the function a nice name (getGreeting). Notice the signature preview show what parameters the function will be created with.
The Page_Load after generating the getGreeting function - nice and easy to read ;-)
The auto generated function takes 2 parameters and return a string