SharePoint 2013 The name 'InitializeControl' does not exist in the current context

The storyline:

I created a visual web part inside my VS2012 solution. Every time I saved the ascx file I had to wait for a few seconds as my VS was 'Communicating with SharePoint'.

If you are the type of person who has an addiction of hitting 'Ctrl + S' after modifying a few lines of code then you will find this annoying.

Then I tried to switch my solution to 'Offline' to avoid this. I wrote my code and when I did a build it throws me this error. After further investigation it seems that my ascx.g.cs file disappeared.

Now I know why it was 'Communicating with SharePoint' every time I saved the file. It's generating the g.cs file that has the InitializeControl function.

 So to get it back working, I just switched to online mode, then re-saved my ascx file and voila! my g.cs shows up again. 

Interested to see if other people have any ideas to make this faster process.

HTH,
Andreas

SharePoint 2013 Rest API and Knockout JS

Hi all, Most of the times in public facing websites you want to have a nice fast interaction for users to be able to get the information and we want to display it in a nice looking way. For example a simple question with responses like this:

where user can click Yes or No and the response will show and they can go to the next question. 

To achieve this we can easily leverage SharePoint capabilities for storing the questions in the list and access them through the REST API. For rendering and interaction we will use the mighty Knockout JS making it all nice and easy.

First step is to create your SharePoint list to store your questions:


Then you can create a web part to host this little wizard. In your visual web part ascx file, the first thing we want to do is to create a viewmodel and get the data from our list. Using the REST api and with the help of knockout mapping (or wrap) we can get our observables easily. Below is the complete js on my page




Then in our markup we can use the awesome native knockout template to do our rendering logic:



And there you go! Very fast to build a simple wizard/tool/quiz this way. This is assuming no sensitive data in the back end because then it will be exposed through client side technology. If so then you have to mix it with server side technology to protect and secure your application.

Hope this helps,
Andreas

CRM 4.0 Useful FetchXML Javascript Helper

Hi again,

Although most of you would say CRM 4.0 is outdated, but unfortunately some companies are still using them :) (I know we are in the process of migrating).

However just want to let you know I found a post here that provides useful javascript function to retrieve record through fetchXml. It is useful for let's say based on the lookup id you want to get all the attributes and populate other fields in the form.

I have extended that function so you will be able to get attribute lookup name as well (if you want to populate a lookup field).


To use it you can do something like this:


Hope this helps,
Andreas

Mixing User Controls with Knockout JS - How to make it work

Hi all,

Just want to let you know quite an awesome way of building your web form or application using by mixing server side and client side technologies. The trick of using knockout js wrapped in separate user controls is very simple: use native binding!

Then you will be able to use normal controls like this:



You can grab all the benefits of fast asynchronous client side script. All server side logic can be implemented using web services. Just keep in mind that it is always better to do validation on both ends (i.e. form validation and saved object validation)

Other tip:
Sometimes when object is too large IE will complain about slow running script. This occurs especially when you are using mapping plugin. Good workaround is to separate your bindings into chunks or just map your properties manually but sometimes using the setTimeout trick works.

Hope this helps,
Andreas