Friday, March 9, 2012

Registering Telerik.Web.UI when used in a webpart

Quick post about another problem I stumbled across. My team decided to proceed using Telerik controls for our webparts. I ran the .msi and installing went just fine.

Also in VS, I immediately noticed the extended Toolbox with all the awesome new controls so I wanted to horse around with the RadGrid to see how it works.

So I created a new webpart in my project and drag-n-dropped the RadGrid control onto the web user controls. It added the following two lines of code:

And added the related assembly to the bin folder of my project and a reference.

But then BOOM! Big fat ass exception thrown; complaining that it cannot find the Telerik.Web.UI assembly

This is how to solve it.

First, go to your Package\Packge.package file, open it and go to Advanced (at the bottom). Next, click 'Add'->'Add existing assembly...'. Find the dll and then add a new item to the Safe Controls section, where you fill out the Namespace and the Assembly Name. Make sure that the Deployment Target is set to the GlobalAssemblyCache

Then, open the VS Command Prompt, and execute the following command line:

sn -T fullpathtoyourassembly

This wil give you the PublicKeyToken which you will use in a minute. Close the prompt and go to the folder where your dll is residing. Right-click it, choose properties -> Details and take note of the File version:

Finally, go back to the .ascx file and in the Register element, extend the Assembly attribute with the following:

<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI, Version=2011.3.1115.35, Culture=neutral, PublickKeyToken=121fae78165ba3d4" %>

That should make it work!

Enjoy ur weekend!

No comments:

Post a Comment