It has been a while

It has been a while since the last blog.
Dealt with lots of different technologies…. Time to do something new.. Something I wouldn’t neccesairely need but something which would be very good to know.

Powershell it is. Got myself the Powershell in Action book an started reading.

The idea is to have lots of snippets I learnt/need listed for myself and anyone else.

Let’s get it started

Posted in Powershell | Leave a comment

ASP.NET MVC 3.0: How do I return just the content of a partial view and not the partial view as a whole html doc

The question I posted on the ASP.NET forum today bugged me for a bit:

With Razor how do I return just the content of a partial view and not the partial view as a whole html doc?

Currently with the aspx engine in 3.0 I just create a partial view (e.g. _Test.ascx) with some basic html:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<dynamic>" %>
<b>test</b>

 My HomeController looks like that:
 public ActionResult Test()
 {
      return View(“_Test”);
 }

When I call it in the browser (e.g.: http://localhost:2010/Home/Test) I only get <b>test</b>
back.
I use this in ajax calls to replace the content of a page. I love this feature.

If I do the same with Razor, the Razor enginge renders a full html page.
How can I tell the Razor engine to be not so smart and just return the content of the partial view?

Answer:

The reason for your problem is the _ViewStart.cshtml that sets the layout for all pages. As such, even the user control’s output uses the layout and you get the whole darn thing as opposed to the user control content.

1. You can handle this in a number of ways – move your ViewStart file so that the usercontrols are in a folder that doesn’t have a viewstart that sets the layout.
2. Put your user controls in a folder and in the viewstart for that folder, have:
@{
    Layout = string.Empty;
}
3. Put that code at the start of each user control.
Eseentially, just make sure that the Layout for the control is not set to a layoutpage and you should be fine.

See the whole thread on:

http://forums.asp.net/p/1624687/4174586.aspx#4174586

Posted in .Net, asp.net mvc | Leave a comment

ASP.NET MVC

After trying hard to avoid asp.net mvc I finally gave in and gave it a shot. So I went to the asp.net mvc home page and watched Scott’s intro from the european conference.

And I love it! I love it! I love it!

It is so clean and it makes developing faster and it is made to use jQuery to the max

What do I like best?
Not having code behind in the actual aspx page. It is more like a classical asp page with a real datamodel under the hood and lots of html helper functions.
It feels like mvc and jQuery is made for each other. Finally I have a framework which is html, http and javascript focused and not millions of events I have to be concerned about.
Did I mention I can finally test my controllers in a super easy build in way. No weird hooks needed anymore.

I think it is also the right time to make a shift from classical web foms to asp.net mvc.
I feel the industry is ready and mvc is a major state.

I think I am ready for my first production mvc app.

MVC hear I come.

Posted in asp.net mvc | 1 Comment

iPhone, iPad: Getting unique Identifier for device

iPhone, iPad: Getting unique Identifier for device

[[UIDevice currentDevice] uniqueIdentifier]] dataUsingEncoding:NSUTF8StringEncoding]];

Posted in iPhone/iPad | 1 Comment

iPhone, iPad: Setting the network activity indicator in the top bar

Setting the network activitiy indicator (NetworkActivityIndicator) on the top bar:


[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];

Posted in iPhone/iPad | Leave a comment

iPhone, iPad: Timer and CADisplayLink snippet


#define kFrameInterval 1

-(void)startTimer
{
if (displayLink == nil) {
displayLink = [CADisplayLink displayLinkWithTarget:self
selector:@selector(gameLoop)];
}
displayLink.frameInterval = kFrameInterval;
[displayLink addToRunLoop:[NSRunLoop currentRunLoop]
forMode:NSDefaultRunLoopMode];

}
-(void)stopTimer{
[displayLink invalidate];
displayLink = nil;
}

Posted in iPhone/iPad | Leave a comment

iPhone, iPad: AppDelegate_Shared for universal apps

I personal love the way the apple temple for core data supclasses the AppDelegates for universal apps.
I apply this pattern to nearly all of my projects.
Here the snippet:

Add AppDelegate_Shared class to project.
AppDelegate_Shared.h

#import <Foundation/Foundation.h>

@interface AppDelegate_Shared : NSObject {
UIWindow *window;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@end

AppDelegate_Shared.m

#import "AppDelegate_Shared.h"

@implementation AppDelegate_Shared
@synthesize window;
#pragma mark -
#pragma mark Application lifecycle

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

// Override point for customization after application launch.

// [window makeKeyAndVisible];

return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application {
/*
Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
*/
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
/*
Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
If your application supports background execution, called instead of applicationWillTerminate: when the user quits.
*/
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
/*
Called as part of transition from the background to the inactive state: here you can undo many of the changes made on entering the background.
*/
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
/*
Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
*/
}

/**
Superclass implementation saves changes in the application's managed object context before the application terminates.
*/
- (void)applicationWillTerminate:(UIApplication *)application {

}

#pragma mark -
#pragma mark Memory management

- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
/*
Free up as much memory as possible by purging cached data objects that can be recreated (or reloaded from disk) later.
*/

}

- (void)dealloc {
[window release];
[super dealloc];
}
@end

No change both AppDelegate_iPad and AppDelegate_iPhone to:
.h

#import <UIKit/UIKit.h>
#import "AppDelegate_Shared.h"

@interface AppDelegate_iPhone : AppDelegate_Shared {
}

@end

.m

#import "AppDelegate_iPhone.h"
#import "AppDelegate_Shared.h"

@implementation AppDelegate_iPhone
- (void)dealloc {
[super dealloc];
}

@end

Posted in iPhone/iPad | 1 Comment