Loading Custom User Controls in SharePoint

I am writing this post because of the headache I faced trying to load and run a custom user control in SharePoint and the lack of good documentation on how to address the issues I faced. Hopefully this post will help others who are having the exact same problem easily come to some resolution.

WSS 3.0 and Microsoft Office SharePoint 2007 (MOSS) gives one the ability to develop and use custom user controls in SharePoint. Creating a basic custom web user controls is relatively easy and can be done in Visual Studio or notepad if you will. The control is given an extension, “.ascx” and can be loaded into an aspx page and run. In a later post, I will show you have to develop and run a simple custom control in a .Net web environment but in this post I want to talk about an issue I had trying to load and run my user control in a SharePoint page.

After I had created my simple ‘do nothing’ user control, I wanted to make sure that I was able to reference this control and load it into my .aspx page. Once I knew I had the correct references paths and the user control loaded successfully, I could then go in and develop the control. However, two issues arose from this attempt. The first problem was figuring out the path to the user control, the second was enabling permissions to allow the user control to actually run on the SharePoint page.

With regards to the first problem, simply loading the control took a bit time more than I had anticipated since I was not too familiar with the correct paths to use in SharePoint. When you reference your user control in an aspx page, you would use the following code for each user control you load


Of course you will have the code that will load the user control into a placeholder control or panel control or used by another control… To find out how to do so, please read my posting on using custom controls in aspx pages.

The tricky part here is where do you place your user control, then what is the path to insert to point the Src attribute to the user control? What I figured out is that you really want to place your user controls in the CONTROLTEMPLATES folder where you’ll find a number of other SharePoint/WSS 3.0 web controls. This complete path is as follows

c:\program files\Common Files\Microsoft shared\web server extensions\12\TEMPLATE\CONTROLTEMPLATES

As long as this control is in the CONTROLTEMPLATES folder, all you will need in the Register directive’s Src attribute is to point the path to the “/_controls/MyUserControl.ascx”. Your register directive will now look like this


You will know the path is correct because either your ‘do nothing’ control will load successfully and your page will be blank, or you will get an error to the effect that the control you are trying to run does not have permission to run, or you may just get a HTTP 403 Forbidden error.

This brings me to the second issue that I found. I found that SharePoint will not just simply run any user control you drop in there. After working with the web.config file (someone had mistakenly pointed me to the file), I finally figured out that being that MOSS/WSS 3.0 runs on Windows Server 2003 (or up coming Windows Server 2008), I had to go and actually set permissions on the file itself to allow itself to be run by SharePoint/.Net.

What you will do in this case is right click on the file to bring up the properties popup menu and under security, you will need to give the local WSS_WPG group account permissions to modify the user control. While you are at it, you may also consider giving the local WSS_ADMIN_WPG group account the same permissions.

After you have completed the above steps, you should find that your user control will load and run successfully… well in this case, it does nothing, but since you don’t get an error, then you know you have been able to load your custom user control.

The only thing I would add is that you should be able create a folder in the CONTROLTEMPLATES folder where you can store all your user controls and part of that will require that you make some minor edit to the web.config file. I will update this post shortly to include details on how you can do that.

Why Does Evil Prosper?

As I try to make sense of what is going on in Kenya and the realization that a great evil has descended over that country… and the fact that the leaders, whom many had placed their hopes in, continue to remain silent and chaos continues to rage, I find some comfort in sermons such as this one titled “What Christians Should do When the Wicked Prosper”.

Even more profound is this passage from chapter 22 of book of Revelation, verses 10 to 12 that says, “(10)Then he said to me, “Don’t seal up the words of the prophecy in this book, because the time is near. (11) Let the one who does what is evil continue to do evil, and let the filthy person continue to be filthy, and the righteous person continue to do what is right, and the holy person continue to be holy.” (12) “See! I am coming soon! My reward is with me to repay everyone according to his work. “

In light of all that is happening, it makes me realize that even though the wicked seem to prosper here and now, certainly when the die, they will face the great white throne judgment. This is where many will look back and absolutely regret the wicked lives they led while on earth…

I have always wondered what happens to someone after they die, according to my understanding, if they were a believer, i.e born again Christian, then they will go to heaven. If they are not, they will go to hell or hades which is basically a holding place where they await for the great judgment and are judged according to what they have done. Now remember, the bible says that everyone has sinned, and the wages of sin is death. The verdict of the great white throne judgment is the lake of fire and that is what the bible calls the second death. The bible also says that there will be weeping and gnashing of teeth… Now lets think about this for a moment. Many ignorant people will say something like, well I’d rather go to hell because all the cool people will be there and the party will be none stop. Really? is that what you think its going to be like? If God has prepared a place to punish the wicked, and if God is truly just, He indeed must punish the wicked, do you really think He will create a place that you’ll just party on with your dumb little buddies for eternity? One of my other understandings is that you will also be utterly alone. Not only are you suffering, but you are suffering alone… for eternity… for ever…. now think about that for a moment, that, ultimately, that is what awaits the wicked…

Why do the Nations Rage?

Here’s an interesting article that I haven’t got time to read right now but I wanted to bookmark it and come back to it later…

Sadness… Yet Hopefull…

I think more and more of us have come to realize that our leaders really do not look out for the good of the country and the people who elected them into office, they only look out for themselves. Their only thoughts are how can they continue stay in power, how can they make as much money as possible and how can they rule with impunity…

To be honest, I wonder how leaders past, those who stole, killed, looted, from their follow countrymen and the treasury, felt when they died and came into the next reality. I really believe there is more to life than just life. What I mean is that when we die, our souls don’t just go ‘poof’ but enter into the next reality. For the believer, that reality ultimately means heaven or hell (or more accurately, the lake of fire). So where am I going with this you ask? I wonder if these leaders in their passing away, suddenly wake up in the reality called Hades, and the first words out of their mouths is ‘doh!’ Suddenly they wake up in a reality where they have nothing. None of the money they stole, none of the power they welded, none of the assurance that they answer to no one… but they wake up knowing that they are doomed… and there is nothing they can do about it. Certainly no make over…

For me as a believer, and despite all this stuff that’s going on not just in my country of Kenya, not just what’s happening in Africa and in many parts of the world, my only consolation is that for those who suffer, and are in Christ, death is truly liberating and those who love wickedness will certainly face the Judge and account for all they have done… and not done (if you were a leader)…

Kenyans Seeking Refuge Die as Mob Burns Church


A Kenyan man leads his children away from his neighborhood as he flees violence during disturbances in the streets of the Mathare slum in Nairobi, Kenya. At least 35 children and adults sheltering in a church were burnt alive by an angry mob in Kenya Tuesday, as an eruption of election violence threatened to tip over into a full-scale tribal conflict. (AFP/Tony Karumba)
Source: Yahoo News.

The Kenyan and the International news agencies and others are reporting that a mob targeted and set fire to a church where over 200 innocent Kenyans including women and children were seeking shelter from the violence that started in the wake of the flawed election results. At least 35 Kenyans died in that fire. These thuggish mobs who have been looting, robbing and burning houses and businesses belonging Kenyans, mostly of the Kikuyu tribe.

This attack on innocents, especially those seeking shelter in a church, is a new low in Kenyan violence… honestly, this is a new low.

Blog at WordPress.com.

Up ↑