How To Create SharePoint 2010 custom visual webpart properties


If you’ve created SharePoint 2010 classic web parts before, you know that you can easily define custom web part properties which your web part code-behind can consume.


With the popularity of SharePoint 2010 Visual Webpart, you’re probably interested in having custom properties defined there too.

There are few things different about exposing your custom properties in a Visual Web part.

Let’s see the steps involved:

  1. Add new or use existing Visual Web Part to your project, in our case called Webpart1
  2. Open the Webpart1.cs file which will look something like this:
  3. and add your custom property definition right below the CreateChildControls method, in our case the property will look something like this:

    In here, the PropertyValue is the actual variable which will be later consumed by your web part user control.

  4. Update your CreateChildControls logic to look like this:
  5. This piece here will pass in the properties every time the control is reloaded. In here, the only change you’ll need to make is to rename Webpart1UserControl to the [name of your webpart]UserControl. This will reference the ASCX used for the Visual Webpart.

  6. Switch to your user control … Webpart1UserControl.ascx.cs
  7. and define public variable right below the class declaration:

    Here the Webpart1 is referencing the actual web part class file (not ASCX).

That’s all, in your code you can get a hold of the web part property value by using this: this.WebPart.PropertyValue, where the PropertyValue is the name of the variable we’ve chosen earlier.


This article was originally posted on Yaroslav’s blog at

SharePoint - Intranet Tools: The User Adoption Activity Listing


2011-11-29-UserAdoptionActivityListing-01.pngI have released a new tool that I use when working with clients supporting effective user adoption. This tool is a listing of over 50 commonly used User Adoption Activities. The purpose of this listing is to help highlight other activities or methods organizations are using to improve user adoption. You may find some activities in the listing that resonate with your organizational culture and business need, and hopefully the short description will help make sense of how to go about executing or implementing that User Adoption activity.

A short time ago I finished another presentation at Share Australia where I highlighted quite a few different user adoption activities and techniques. In the spirit of sharing some of the tools and techniques I have found that work well for me and my clients I present to you the first draft of The User Adoption Activities Listing.

I was going to wait to release this with much more comprehensive definitions of the activities, how complex they are, and lessons learned from implementing them, but I am hoping even in a partial draft it provides immediate value to many people.

To be clear I have been involved in implementing every one of these activities with one organization or another (and some I have done multiple times with various degrees of success). So everything on there (even if it’s a bit hastily written) is something I have seen a degree of success with.

When I worked with many clients I encountered a challenge that sounds something like this:

  • Business: “I think one of our biggest challenges is user adoption. Do you have any advice?”
  • Me: “It depends. What are you using SharePoint for? What are you trying to do with it?”
  • Business: “We use it for… blah blah blah.”
  • Me: “Well for company XYZ who was doing the same thing they found success in doing the following user adoption activities (above and beyond just doing a darn good job of implementing effective business solutions).”
  • Business: “Oh I hadn’t thought of that. Thanks!”

The challenge was that over time there was quite a bit of repitition in stories from myself, as well as confusion from each new participant in regards to what adoption activities other companies were implementing. Some of the activities really relate more to specific features in SharePoint, and some are broader in their application. So I thought, if nothing else I can at least share a bunch of them and update the layout and structure with more context over time.

Clients always tell me new stories, or come up with enhancements or modifications to the activities every day. So don’t feel like the short descriptions are limiting, and use the ideas as inspiration for how you might want to tactically improve user adoption.

If you find it useful please feel free to share or look into other things I have been working on as well:

Hope this helps,

Parent-child-grandchild relationship in SharePoint 2010 lists with javascript only


I got this request:

Hi Alex,

I am new to SharePoint and have been struggling with steep learning curve and would really appreciate your help…

I created a parent-child-grandchild relation where I inserted a related view in the parent’s dispform to show all children and also in the child’s dispform to show all grandchildren. I’ve also followed to set the parent’s ID on the child’s newform using javascript but I need to take it a step further. In the child’s newform I need to retrieve the parent list’s 2nd field and use that value to build a dynamic drop down field in the child’s newform. The field items in the drop down preferably to be pulled from another list for the ease of maintenance but hard coding is also acceptable. This is probably a no-brainer for you so I hope you wouldn’t mind spending some time on it and I will make sure some donation is made . Thank you so much!

This involves putting scripts in NewForm and/or DispForm in three lists. Please follow the steps carefully.

Please note that this code is for SharePoint 2010 only.

Step 1

Create the three custom lists used in this example:

  • Parent
    This list has the Title field only.
  • Child
    Add one field of type Lookup (single choice) with the name “Parent”. This lookup should target the title field of the "Parent" list.
  • Grandchild
    Add one field of type Lookup (single choice) with the name “Parent”. This lookup should target the title field of the "Child" list.

Step 2

Download the code from here

The code is presented in individual folders so it’s easy to get the right code in the right form.

Step 3

Edit the code that goes in the CEWPs to fix the script src attributes in all files, the “childListUrl” in the DispForm code and the various “argObj” variables if your lists or fields has different names. You will have to read trough the code for the CEWPs to find the bits to change.

The file “ParentChildResources.js” does not need any modification.

Upload the code to a shared document library and maintain the folder structure (or rename the files so that you know which file goes where).

Step 4

Add CEWPs to the list forms and insert the code corresponding with the folder and file name. It is important that you use the content link option to link to the code.

To add a CEWP, go to the list, activate it by clicking in the “list area” to bring up the list tools ribbon. Select the tab “List” and “Form Web Parts”.

You find the content link option like this:
Edit the page and activate the CEWP. In the ribbon toolbar, select “Web Part Tools” and then “Web Part Properties”.

To ensure you get the correct file path, go to the document library, right click the file and select “Copy shortcut”. Paste this URL in the content link field. You might want to edit the URL to make it relative.

Note Add the CEWP below the list form.

The result should look like this






Final words

This solution uses the Client Object Model introduced in SharePoint 2010 and therefore it will not work on previous SharePoint versions.

To keep this solution clean and simple, the last bits from the request regarding the lookup column, are kept out of this post – it will be emailed to the requester.

If there is demand for it, I will post it as an appendix to this post later on.

Hope someone can make use of this code.

Using minified CSS and JavaScript files everywhere in SharePoint 2010



In my previous post I showed you how you can automate minifying JavaScript and CSS files in Visual Studio 2010. As I also mentioned, SharePoint has limited support for using minified files. But just because something is not available out of the box doesn’t mean it’s not possible. Find out how to leverage the extensibility capabilities of the SharePoint 2010 platform and support using minified CSS and JavaScript files everywhere.

Minified files and the ScriptLink control

Using minified files is a great and easy technique for optimizing your SharePoint solution for performance. Out-of-the-box SharePoint 2010 provides the ScriptLink control which allows you to automatically switch between raw and minified versions of your files. However, it has two flaws. First of all it supports only JavaScript files and just as you can minify JavaScript files, you can also minify your CSS files. Another thing that you have to keep in mind, if you want to use the standard ScriptLink control with minified files, is that it works only for JavaScript files deployed to the LAYOUTS folder on the file system.

Using minified files everywhere

If you want to use minified CSS and JavaScript files everywhere you will need a solution other than the standard ScriptLink control. One solution that you could consider is creating a custom control that you would add to your Master Page and which would automatically switch between the raw and minified version of the asset file depending on the mode in which the Web Application is working. Such control could look as follows:

How it works

We start with retrieving the URL of the asset (line 21). To provide flexibility when defining URLs we first translate the URL to a server-relative URL by parsing tokens if applicable (line 39). Next we get the type of the asset that we are working with (line 40). While we could create two separate controls: one for CSS files and one for JavaScript files, in this sample we use one control for both types. The last step is to check whether the asset link points to an asset that is provided in two versions (raw and minified) and if the Web Application is in debug mode (line 42).

Using the WithDebug property allows us to use the AssetLinkControl both for referencing files that have already been minified (like the jQuery library) as well as files that we have created ourselves and that are available both as raw and minified files.

If the Web Application is in debug mode we convert the asset link to point to the debug version of the asset (line 43). Finally we return the URL and render it depending on the asset type (lines 23-30).

Using the AssetLinkControl

The AssetLinkControl can be used the best for declaratively registering assets in the Master Page and Page Layouts. To register an asset, all you have to do is to include the following snippet:

Depending on the mode in which your Web Application is running, this control will either point to the minified or the debug version of the CSS file.

What the AssetLinkControl is not

Although the AssetLinkControl provides you with great flexibility, it is by no means a replacement for dynamically registering JavaScript or CSS files. The standard SharePoint 2010 CssRegistration and ScriptLink controls provide much more flexibility allowing you to determine how and when your assets should be loaded. Whenever you need to register a CSS or a JavaScript file on runtime you should use those standard controls instead. The great thing about how the AssetLinkControl is built, is that you can use its GetAssetUrl method to build a URL to your asset and then pass it to the standard SharePoint controls. This approach allows you to extend the standard functionality of the SharePoint platform with additional flexibility and optimization for performance.

SharePoint Content Slider’s Cousin, the Marquee



In my previous article, I showed you the framework for building your own content slider. Today, while perusing the SharePoint forums on Stack Exchange, I found an interesting post that I thought I’d put to the test, creating a marquee with jQuery. Christophe has already tackled this with his great series on html calculated columns and an example can be seen here. I thought since I had already done this in the past, utilizing that framework to create a similar output would be a snap.

This technique wouldn’t have the same type of scope like my previous article. This marquee could be used to display breaking news or special alerts and not full-fledged announcements.

To get started we need some of the usual suspects and one new library to add to our toolkit. Download, unzip and upload them to your scripts library.

To start off, we need to properly reference the resources:

<script type="text/javascript" src="http://yourSPDomain/sites/site/library/jQuery.js" ></script>
<script type="text/javascript" src=" http://yourSPDomain/sites/site/library/SPServices.js" ></script>
<script type="text/javascript" src=" http://yourSPDomain/sites/site/library/ jquery.marquee.min.js" ></script>
<link type="text/css" href=" http://yourSPDomain/sites/site/library/ jquery.marquee.min.css">

Then we need to build up the markup to populate the html structure that the marquee library needs. From the web site documentation, all that is needed is an unordered list. This makes the markup generation very simple. I’m reusing a good portion of the jQuery from my previous article so I’m not going to go into depth on what’s happening.

<script type="text/javascript"> 
  $(document).ready(function (){
   var emptyResults = "<li>There are no current alerts.</li>";
   var toShow = false;
    operation: "GetListItems",
    async: false,
    listName: "Announcements",
    CAMLViewFields: "<ViewFields><FieldRef Name='Title' /><FieldRef Name='Body' /></ViewFields>",
    CAMLQuery: "<Query><OrderBy><FieldRef Name='Created' /></OrderBy>" +
    	 "<Where><Or><Geq><FieldRef Name='Expires' /><Value Type='DateTime'>" +
               "<Today /></Value></Geq><IsNull><FieldRef Name='Expires' />" +
    completefunc: function (xData, Status) {
     var itemCount = $(xData.responseXML).find("[nodeName='rs:data']").attr("ItemCount");
	 if(itemCount > 0){
	  toShow = true;
	   $(xData.responseXML).find("[nodeName='z:row']").each(function() {
        var bodyHtml = "<li>" + $(this).attr("ows_Title");+ "</li>";
	 else { 
	if (toShow == true) {
<ul id="marquee" class="marquee" />

Instead of build a large html structure like before, the SPServices script is simply creating a list item (li) for each record returned. These get appended to the unordered list (ul) and thus the marquee is born. The plugin does allow for options to be passed into the function call to let you tweak how the marquee functions. You can read about those options on the plugin page. To see a working example, check out my sample page.

Turkeys and Waders


2011-11-19-Turkeys-01.pngWe’re taking the next two days off to spend time with friends and family and celebrate Thanksgiving. We’ll be back on Monday, hopefully well rested and definitely well fed.

As for me, I’ve made my annual journey to Grand Rapids, Michigan to be with my family. One of my Thanksgiving traditions is to walk down to the beautiful Grand River where I’ll watch the fishermen. No matter how cold and snowy it gets (today it’s 25 degrees), these dedicated guys put on their waders and step into the frigid rushing water in the hopes of "some good steelhead action". Some do it for the love of the sport'; while for others it’s a necessity. But whatever their reason, they always smile and give me a wave.

I am thankful for so many things in my life. But at this very moment I’m pretty thankful not to be standing in the Grand River…

Happy Thanksgiving!

How To: Working SharePoint 2010 modals


When working with custom SharePoint modals, you’ve got to be able to collect the user data and then allow them to close the modal.

In my last post, we looked at how you can create a new modal rendering your custom page right from the context menu of the SharePoint list item.

This time I’d like to show you how you can close your modals once users are done with them.

There is no magic to closing modals, there is a button as you’d expect. The thing to keep in mind is that your modals are part of the context of the entire page and JavaScript is used to either show them or hide them. The whole superimposed modal UI is just a visual trick.

The close/cancel button is easy, you just close the modal DIV. There is even an out-of-the-box function for that.

All you need to do in the page that renders in modal is to assign OnClientClick event as follows:

The commit and close modal logic is a bit different since you need to run to the server first, execute any server events, and only then execute a client script.

The idea here is to execute a client script on the post-back when your custom server side code has run.

In our example, our server side context executes on a button click. We would add the following after the click has executed its server events:

The difference here is that we call commitPopup JavaScript function and we write this statement only when the page has posted back after our server code has executed.

As a result your users will see a modal dialog refresh and disappear.

Try it out!

This article was originally posted on Yaroslav’s blog at

SharePoint: Fixing that Pesky People Search Web Part Issue


The People Search Web Part has a known flaw with regards to the font size shown in the web part when conducting a search. When I came across this issue recently I immediately went to my handy dandy toolbox I affectionately call “Bing”.

Immediately, I could see that others have seen this issue and there is a fix. Raja Dandu has a great piece on it “People Search WebPart Font Fix”. While he does show the code needed it does not exactly explain how to implement the solution if you are not familiar with CSS. John P. White refers to Raja’s fix in his response to this question on MSDN’s Social site and adds the caveat that you have to set your Alternative CSS to a custom CSS file. Again if you are not familiar with CSS you now have two valuable pieces to the puzzle to solve the issue, but you still may not be able to fix it. Finally, if you read the comments on Raja’s posting you will see a comment by Marco Valli (Vallimarco) referring you to which talks about using Internal Style Sheets. So now I have the method, the solution and the syntax to use. But again if you are not familiar with using CSS you could find yourself with information you can use to correct the flaw, totally clueless as to how the pieces fit together.

Which is why I wrote this post to combine each of these together in what I hope is an easy to implement solution. Before I begin I would like to thank my colleague Alton (A. J.) Young Developer Extraordinaire over at General Physics for explaining to me how to use the solution. As someone who is not a coder I would never have been able to figure this one out. Okay, on to the solution:

  1. Copy the code that Raja has in his post. Just in case this post is seen five years from now and Raja’s post is not available the code is listed below:
  2. .s4-search
    border-bottom: #e3e3e3 1px solid;
    border-left: #e3e3e3 1px solid;
    padding-bottom: 0px;
    padding-left: 3px;
    width: 191px !important;
    padding-right: 3px;
    background: url( #fff repeat-x 0px -511px;
    height: 17px;
    font-size: 13px;border-top: #e3e3e3 1px solid;
    border-right: #e3e3e3 1px solid;
    padding-top: 2px;
  3. Open yours and mine favorite html editing tool Notepad and paste the code into a blank document.
  4. 2011-11-18-PeopleSearch-01.png

  5. Okay so now you have the information for the correct sizing that needs to be used. Now you have to tell the web page what this code is to be used for. You will need to add the following to the top of the code you previously pasted into the dialogue box:
  6. <style type="text/css">

  7. And you will need to add the following to the bottom of the code:
  8. </style>

  9. In the end your notepad document should look like this:
  10. Save this document someplace easy to get to.
  11. Open the site that you would like to have the People Search Box implemented on.
  12. Upload the text document to the Style Library for the site. I guess it does not really matter from an operational view where you upload the file. I just prefer to keep things organized.
  13. Right click on the document you just uploaded into the library and choose the properties option.
  14. Copy the address listed in the Address URL.
  15. 2011-11-18-PeopleSearch-04a.png

  16. Press the Cancel button.
  17. Navigate to the page that you would like to have the People Search Box used on.
  18. Select the Page Tab and select the Edit Page Option.
  19. 2011-11-18-PeopleSearch-05.png

  20. Select the zone that you want the web part to appear in and select the “Add a Web Part” option.
  21. Insert the People Search Web Part into the page.
  22. Insert a Content Editor Web Part in the page. Make sure that you insert both Web Parts in the same zone.
  23. If you click inside the People Search Web Part you will notice that the font is about a size 6. Too small for most people to read effectively.
  24. In the Content Editor Web Part click the small down arrow and select “Edit Web Part”.
  25. In the Content Link Box paste the URL for the text document.
  26. Click the plus sign adjacent to the Layout option.
  27. Check the “Hidden” box
  28. Click OK.
  29. 2011-11-18-PeopleSearch-08.png

  30. Now test your search box’s font size.

Note: In step 21 I had you hide the Content Editor Web Part. This is due to not wanting to show the underlying code to the users of the site. You can select to have it shown if you wish.

My Top 5 Reasons: Why absolutely everyone should attend a SharePoint Saturday


Training is expensive. Really good training is really expensive…or so I thought, until I discovered SharePoint Saturdays. I found it by accident. I was researching which presentations I should attend at my first $1000 conference and Laura Rogers had a schedule on her site that included a SharePoint Saturday. A little more digging and I found I nearly fell out of my chair when I learned this existed and I hadn’t heard of it yet! (I wasn’t on Twitter at the time2011-11-14-SPSaturday-02.png)

What is SharePoint Saturday?

It is a one day FREE mini-conference that includes awesome sessions about SharePoint. These sessions are targeted towards new users, current users of all skill levels, developers, decision makers and anyone else that has even heard the word “SharePoint”. There are usually four or five 50 or 75 minute sessions running at the same time for different target audiences on all kinds of subjects, such as BI, jquery, Search, Designer, content management, governance, best practices, use cases, etc. etc. etc. These sessions are led by Microsoft MVP’s, consultants, community experts, developers, architects and end-users that have something really cool to share. Many of these speakers are the SAME speakers that you will pay $1000 or more to see at the big conferences (which are worth every penny, by the way)! These awesome individuals donate their time to these events out of a love for SharePoint and the community. Plus you usually get some pretty cool swag (shirts, bags, usb drives, etc).

Free? So what’s the catch?

It’s impossible to get something for nothing…right? Wrong! That’s just the point…there is no catch. SharePoint Saturdays are run by volunteers, the speakers are volunteers and the sponsors take care of everything. You are not forced to buy anything, listen to a sales pitch or even visit the sponsor booths…though, I highly recommend doing so since they have great information and some pretty cool swag. There are always really great giveaways that you are eligible for or can sign up for at the booths. Each of the six SharePoint Saturdays I have attended have given away at least one xbox with Kinnect (I won one in DC2011-11-14-SPSaturday-02.png). The only cost or requirement is your Saturday time.

OK, so now to my point…here are my top 5 reasons everyone should attend a SharePoint Saturday:

Awesome Sponsors

The sponsors of SharePoint Saturday are vendors that offer products and/or services revolving around SharePoint. It’s amazing what you can learn about the capabilities of SharePoint that you never knew were possible until you talk to these guys. You will find ways to make your SharePoint solution better and usually end up saving money for your company in time/development/productivity. They may be SharePoint extensions, hosting services, consulting services, training and more. Many of these companies were created because someone has felt your pain points before and created a solution for it. Sponsors pay for the entire cost of the conference, which I find amazing. I make a point of visiting each new sponsor I come across to learn about what they offer and determine if it might be something our company or a customer might need.

Knowledge is Power!

I don’t know about you, but I don’t have a lot of time to search and find all the latest and greatest best practices and techniques about every aspect of SharePoint. I mean…SharePoint is HUGE. Even though I have been a SharePoint Power User for 10 years, I still find new things every day. SharePoint Saturday is a great way to get a “taste” of a lot of information about a lot of different subjects. You won’t walk out of every session as an expert on every subject, but hopefully you’ll learn something new that you can then make an effort to learn more about. Why re-invent the wheel or have major/minor issues if someone is willing to let you learn from their triumphs and mistakes? The truth is that there is so much that SharePoint can do that that you may not know about….you just don’t know what you don’t know. And if you discover something that you want to learn more about, you’ll be at the right place to find the best training vendor or blog to meet your needs (either as a sponsor or ask a community member) that targets what you need.


I cannot sing the praises of the presenters enough! In general they are extremely friendly, smart, witty and fun people who are passionate about what they do. I absolutely love meeting and conversing with as many of the presenters that I can. I will honestly say I haven’t met a presenter I didn’t like…and between SPTechCon 2011 and 6 SharePoint Saturdays this year, I have met a lot! This is the most friendly, fun and smart group of people I have had the pleasure to be around.


By attending these sessions you become a part of an awesome community. If you embrace it, it will enhance your SharePoint Experience. I have had some great idea-exchanging conversations with other attendees who experience similar pain points we all have. There are so many ways to accomplish the same thing in SharePoint and so many people have done so much. This is a tight-knit community and if you are looking for an expert in a certain area, someone in the community will be able to point you in the right direction.

Free Stuff

On top of the all the free training you’ll get, you get lots of swag (and good swag too!) plus breakfast, plus lunch, plus the chance to win really great prizes (valued from $25 up to $400+). This all adds up to one great time! Additionally, you may even get a free beer (or soda if you’re under 21 or not a drinker). No, not at the conference, but at SharePint, which is a very social event where the speakers and attendees congregate to partake in lively discussions and raise a glass to the community at the end of the day. And don’t be shy at these things…people are there because they WANT to connect with other SharePoint people.

I know I’m leaving a lot of important things out, and I hope my fellow community members will comment on this note with additional reasons why people should attend SharePoint Saturdays. I am just so impressed with the amazing job the SharePoint Saturday organizers do that I want everyone else to see it too.

I hope you will find the next SharePoint Saturday near you at and sign up today. Check the site often, new dates and locations are announced all the time, or make it easy and sign up for the newsletter. Share this with your fellow SharePoint users…please don’t assume that because you know about the community and all it offers that your friends, co-workers and clients do too. It’s up to us to spread the word. The more users that are educated on how to use this powerful tool, the more SharePoint will blossom, which will increase demand for more products and services to make people’s lives easier and we all win.

(And no, I am not an organizer or a sponsor…I am just a really passionate attendee that wants to share the wealth of this amazing resource!)

And one final word…these events do fill up fast. If you RSVP and can’t make it, please let the organizers know so that someone on the waiting list can get in. OK, I’m off my soapbox now…you can get back to work and have a great day!

How to Create a Company Notification System in SharePoint Part - 4


My co-worker, Erik Boode, talked to me about my company notification system solution. Erik has to implement this solution for one of our customers and he actually found a solution to set fields at read-only! This is really important for the following screen:


You can see in the screenshot that I had to manually enter a warning text. The reviewer is also able to edit the text of the employee. Erik found the following solution:

Open SharePoint Designer and go to the Review Notification form of the Notification list. Click on a control and in the code field change the following:




The controls now become read only! How cool, and pretty easy, is this :-) Check it out:


The only problem we still have is that employees can open this reviewers edit form. Hopefully we can find a solution for this.