Category Archives: VS 2010

JavaScript Visual Studio snippet for is object defined check

Since I write a lot of JavaScript currently in Visual Studio these days, I lack one of the very common checks in JavaScript and that is testing if object exists.

I mean this check :

if (typeof (someObject) !== 'undefined') {

someJSCodeHere();

}

If you want to use this code but not type it each time over and over again and speed your work up you probably thought a snippet that would save your keystrokes would come handy, but there is none in vanilla VS. So, you can use my snippet ,just import it to Visual Studio from Code Snippet Manager window (in VS 2013 – CTRL + K + B) and use it with typing def and then tab (or use CTRL + K + X and pick one).

Enjoy your speedup while working with JavaScript.

PS : do you know you can share snippets with your team mates?

http://blogs.msdn.com/b/zainnab/archive/2010/08/19/sharing-snippets-with-your-team-vstiptool0075.aspx

http://blogs.msdn.com/b/saraford/archive/2007/12/14/did-you-know-how-to-share-code-snippets-with-your-team.aspx

PS2: If you want to edit snippets in you VS, this plugin might be a good idea : http://snippetdesigner.codeplex.com/

How to build Visual Studio solution even if some of TypeScript files are not compiling

The problem :

If you are working on some ASP.NET project and you need to build it even if some files are unbuildable/will not compile (currently I apply this on TypeScript files but this solution is general) , because you for example need to change some other functionality and than continue with TypeScript work than you have a problem.  VS stops building the app and you will have only Yellow Screen Of The Death note with “Parser Error” and “Could not load type – your project name” which I suppose is caused by not generating the assembly.

So, the solutions are (among others) :

  • Exclude erroneous .ts file (which will make it not compile),
  • Say to build system to not compile particular file with something different.

The solution :

It really is simple : just set Build Action from TypeScriptCompile to None and you are done.

ts-build-actions

The strange thing is, that my Visual Studio 2013 will anyway say I have errors, but the build process is not stopped and I am able to run the app.

If you have any other solutions than feel free to post them in the comments. Thanks in advance.

How to access columns, all properties and data of Telerik’s MVC Grid on client

If you want to access all data in your Grid that you have in DOM in your browser on client, you maybe found this helpful link to Telerik’s help page :

http://www.telerik.com/help/aspnet-mvc/telerik-ui-components-grid-client-api-and-events.html

But looking at all those events that are out of box, you maybe eventually need to access all columns or data that you have in grid or tweak some things on client. Then direct access to grid in DOM would be much appreciated.

Answer is in fact on page above, it’s just not that obvious, until you inspect all the elements in DOM you have once page loads.

$('#id-of-our-grid').data('tGrid');

This will give you element with properties like :

ajax – and all URLs that will grid use, columns, data, currentPage, dataSource, modelBinder, etc…..

Just try it and you will see 🙂

Hope this helps.

How to hook to client keyboard events with Telerik’s DropDownList

So, you have same problem as me, how to subscribe to clients keyboard events with Telerik’s DropDownList control for ASP.NET MVC? 🙂

Unfortunatelly, there is no out of box event for this yet, but it’s not that hard, we just need some jQuery magic.

This is the code :


$('#id-of-your-combobox').parent().keydown(function (e) {
alert('Handler for .keydown() called.');
});

Please be aware, that if you are using combo box in Grid (in Telerik’s MVC Grid, like I do), then you need to execute this code in OnEdit event handler, since combo box object exists only when some row is in edit state.

If you have any questions, feel free to ask.

Hope this helps, at least to save you some time.

The Web project blablabla requires missing web components to run with Visual Studio. ASP.NET Web pages with Razor syntax

missing web pages with razor syntax

Ever encountered this strange popup in VS2010 after several hours of happily working with MVC? And now VS thinks, that something is wrong with your Razor components?

Well the thing might be, that you just updated from SVN and your web.config file was modified in a bad way, say like this :

  <connectionStrings>
<<<<<<< .mine
    <add name="blablaConnectionStringFullSQL" connectionString="some-connection-string" providerName="System.Data.SqlClient" />
    <add name="blablaConnectionStringFullSQLalt" connectionString="some-connection-string" providerName="System.Data.SqlClient" />
=======
    <add name="blablaConnectionStringFullSQLalt" connectionString="some-connection-string" providerName="System.Data.SqlClient" />
    <add name="blablaConnectionStringFullSQL" connectionString="some-connection-string" providerName="System.Data.SqlClient" />
>>>>>>> .r199
  </connectionStrings>

Well at least, this was my case, so as a first shot, take a look at files that conflicted after update.

Hope this helped a bit.

No tests were run because all loaded or selected tests are disabled problem in VS 2010

I want to share with you one really nice pitfall I faced at work and that is this nice note once you want to run unit tests inside VS 2010 saying :

No tests were run because all loaded or selected tests are disabled once you try to load and run some of them.

vs2010 unit tests problem

Hmmm, now what? Hitting CTRL + SHIFT + B will build whole .sln and there is no compile time error (but under my conditions, please read whole article if you want to know more).

In general the reason is : In your test solution is some kind of problem, possibly build problem and VS can’t load it and run tests, there is nothing to load when you cant build it. The reason why you can’t build it may vary.

But hey, you just build the whole damn thing and there was no trace of error in console window. Well, in my case two things met.

  • In our particular solution, we are using WCF service + project that references it and this WCF service reference is used later in another project that connects to the service (everything in one solution),
  • Some colleague of mine just unchecked building of Service part unit test and because we have only WCF reference between Service and its consumer (not in References of project),  then Test project of service isn’t really built.

Then we can have nice error in our .cs test file + whole .sln built at same time like this:

vs 2010 tests error

Nice, isn’t it? 🙂

For better explanation of common architecture here is small UML diagram (hope it’s correct) :

small soa diagram

We can have some functionality in class libraries (multiple ones) + unit tests regarding their functionality. Then we expose this functionality as service via WCF service.

Chain in which .csprojs are referenced is following : class libraries on service side and then WCF service it self.

Then we have WCF Reference library + things that depends on it like in this picture Web app, or any other app that will use it. Because it makes sense to mark Web app as starting project, if we uncheck building of test project,VS 2010 doesn’t see any reason to build them. They aren’t in chain, nothing really depends on them. At least from VS’s point of view.

In my test proj solution properties what to build can look like this :

test wcf project solution properties

OK, so now you know what happened in my particular case, hopefully this will help some of you to troubleshoot your particular problems. There is high chance, that problem will be very similar.

Small project I used to play with can be found here : https://skydrive.live.com/redir.aspx?cid=78a5783de37d2ebe&resid=78A5783DE37D2EBE!1830&parid=78A5783DE37D2EBE!1782

Enjoy