.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Error when creating a webpart using user controls

Posted By:      Posted Date: October 23, 2010    Points: 0   Category :SharePoint

I received the following error when trying to create a webpart with user controls. 

Unable to cast object of type 'ASP._controltemplates_UserControl_ascx' to type 'namespace.class'. I deleted all the files from the location
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files, but still the same error occurs.
Here is the code for referencing the user control. 

protected const string defaultUserControlPathField = "~/_controltemplates/myUserControl.ascx";
 protected string userControlPathField = defaultUserControlPathField;
 namespace.class tempControl;
UserControl myControl;
 myControl = (UserControl)this.Page.LoadControl(this.userControlPathField);
                    tempControl = (namespace.class)myControl;

Does anyone have an idea about this error?



View Complete Post

More Related Resource Links

dynamic creating controls in webpart


Hello everybody,


My webpart (wss 3.0, VS2005) initialy contain a listbox. Depeding on the selection made a certain amount of textboxes are to be created and rendered. Via these dynamically created / rendered textboxes text can be submitted (via a button), for futher processing.


I am not sure how, or where in the webpart code, to dynamically create these textboxes.


Maybe somebody can give me some advise on this topic.


Thanks in advance









way to prevent creating, loading and rendering previously rendered controls on postback in a webpart

Hi All, I have a web part and a link control in there when i click it, wp displays rows of data below the previously rendered contents...when i debug it ...web part renders everything from the beginning...so just wondering if there is any way to prevent creating, loading and rendering previously rendered controls on postback?Hanif

Error Creating Controls in design view



Some days ago my designer started to show "Error creating control - [controlname] Value cannot be null. Parameter name: parseText" instead of all of my server side controls in all of my web projects - including both framework 2.0 and 4.0 projects. I tried many tips I found on the net, including restarting VS, cleaning the temporary asp.net folders and even I reinstalled the whole VS pack, but I still get the same error.

This occures in both VS 2010 and Microsoft Expression Web 4.

Any help appreciated.



Acessing controls in usercontrol in javascript function where user control hosted in webpart



1how to acess controls in usercontrol  in javascript function where user control hosted in webpart


2)How to retieve values from javscript code to server side

details as follows

StringBuilder controlString = new StringBuilder();
            controlString.Append("<p>" + CurrentPage.ToString() + "of " + TotalPages.ToString() + " </p>");
            for (int intIndex = 1; intIndex <= TotalPages; intIndex++)
                controlString.Append("<li><a hre

"User cannot be found" error when creating My Site after upgrading to SP2 for MOSS 2007



Hope this is the place for sharepoint gurus?

I upgraded MOSS2007/WSS3 to SP2 and since then I have been unable to get My Site to create new sites for existing domain users.

Some of the domain users created their My Site before the SP2 upgrade and they still work. We just cannot create new My Sites for existing domain users.

Now when we try to create a My Site we get this error:

"There has been an error creating the personal site. Contact your site administrator for more information."

I checked the event logs and usually no error is recorded when this happens so sharepoint does not even give me a breadcrumb (thanks!).

However, on one occassion I did get an event message after fiddling here and there and many attempts at trying to create a My Site, hooray! See below for all the glorious details of the event message, but the basic error is:

"User cannot be found".

I have checked the My Site settings of shared services (SSP1), veiwed user profiles, all the domain users are imported. So I have no idea why when creating a My Site it fails?

I have searched many forums and although they get the same error it seems to be for different reasons so the solutions don't help my situation.

Is there somewhere in Sharepoint that these domain users need to exist? Would I be able to c

Error in creating User through ASP.net website administration tool


i am creating some users and assign them different roles through website administration tool but when i am going to create new user all time validation control display same error and user could not created


Password length minimum: 7. Non-alphanumeric characters required: 1.

There has been an error creating the personal site. User cannot be found


Few of my Domain Users are able to create MySite and few of them are not, though they are having same permission.

There has been an error creating the personal site. Contact your site administrator for more information.

Event Viewer is showing :

My Site creation failure for user 'DOMAIN\username' for site url ''. The exception was: Microsoft.Office.Server.UserProfiles.PersonalSiteCreateException: A failure was encountered while attempting to create the site. ---> Microsoft.SharePoint.SPException: User cannot be found.

Below are the DLL versions of my installation. 

Microsoft.SharePoint.Portal.dll : 12.0.6420.1000

Creating Sites/Lists/List Items under Current User Context in SharePoint By Using SPUserToken

Usually we do this by performing the action under RunWithElevatedPrivileges method and updating the listitem using SPListItem.SystemUpdate() method (see here). but this approach has its own flaws like (RunWithElevatedPrivileges will run under system account, we cannot use SystemUpdate for SPSite,SPWeb,SPList, since it runs under system we will "CreatedBy" by as SystemAccount).

Creating Dialogs and Ribbon Controls for SharePoint 2010

SharePoint 2010 provides new user interface components, such as server ribbons, and the new dialog platform. As a developer, you can create controls for the server ribbon and dialog boxes for the dialog platform.

UI Datepicker and web user controls



I have developed an application using the Master-Detail pattern described in this Matt Berseth article.

The only difference between Matt's article and me is that I am using a FormView object in place of a DetailsView.

Everything works fine except that the formview object, in my case it's inside a user control and I can't figure out how to use the jquery datepicker UI plugin.

I have tried to put the script block for the datepicker either in the aspx page as well as inside the user control but in both cases the calendar does not come up when the related textbox get the focus.

Any suggestion on how to work with the datepicker inside an ascx?

thanks in advance!

create user wizard login error message dont show in a message box?




i am using create user wizard and capturing other information within content template when a new user

registers. Some of the textboxes are binded to required field validators.


there is a validation control on the page and ShowMessage box is True.

If they dont complete some of the text boxes then the message box pops Up with the error message.

It does not however include information errors like "User already exists" or Email address already exists

from the create user wizard membership  UserName and Password Textboxes


is it possilbe to hook all of these up so I get one message box with all errors including membership ones?




Creating a user friendly alias for the website path


 Hello mates,

I am hosting my ASP.NET application on a Windows 2003 Server.

To browse to my application one has to type the path :http://serverName/applicationName

I want users to only type  applicationName on the web adress area.I believe there is something to do with alias and CNAME on DNS records that can adress this.

Any help on how to go about doing this will be highly appreciated.

Registering controls of current assembly object reference NOT set error


Hi There,

I have created a simple ASP.net Web Application (2.0) and have added a web user control.

Now in my page I have added this control but I have registered like this,

<%@ Register Assembly="WebApplication1" Namespace="WebApplication1" TagPrefix="Custom" %>

Which means I want to access all the controls in my current Web Application project

Then I have added my user control like this,

<Custom:MyUserControl ID="MyUserControl1" runat="server" PublicProperty="Hello" />

Every thing is fine but when I execute the project, NO control on my user control gets "instantiated" and thus I receive error "Object Reference Not Set"

Note that My Control has,

1) Public property PublicProperty as String

2) 1 Label control

In Load Event Handler I am setting Text property of Label Control to PublicProperty. Here object reference NOT set error occurs (which means Label control is NOT initialized).

I don't want to register my control using Src, TagPrefix etc. Any ideas?


"Type ASP.x is not defined" error for dynamic user control when publishing updateable


I have a user control (ContainerCtrl) which programmatically instantiates another user control (SimpleCtrl) in OnLoad. It builds and runs fine, but when I publish it I get the error "error BC30002: Type 'ASP.SimpleCtrl' is not defined." (If I publish without the "updateable" option there's no error, but I need the site to be updateable.)

I assume this has to do with the particulars of how the assembly(ies) are built for the different compiler options. My question is, how can I get it to work properly for "updateable" publishing?

VS 2008 / .NET 3.5 sp1

The code follows (web.config is the default from Visual Studio).

Many thanks, Dave


<%@ Control Language="VB" ClassName="SimpleCtrl" CodeFile="SimpleCtrl.ascx.vb" Inherits="_SimpleCtrl" %>

    Simple control


Partial Class _SimpleCtrl
    Inherits UserControl

    'Nothing to see here.

End Class


<%@ Control Language="VB" CodeFile="ContainerCtrl.ascx.vb" Inherits="_ContainerCtrl"

Error on Display user's fullname using Active Directory in asp.net using vb.net



wi As System.Security.Principal.WindowsIdentity =  _System.Security.Principal.WindowsIdentity.GetCurrent()



Dim a As String() = HttpContext.Current.User.

Toolbox: User-Friendly UIs, Online Data Entry Controls, and More


Microsoft® Office is one of the most well-known and most-used consumer products. For many people, their only experience with a computer is when using Office, be it checking e-mail, creating presentations, or writing a document.

Scott Mitchell

MSDN Magazine February 2006

ASP.NET 2.0: Personalize Your Portal with User Controls and Custom Web Parts


ASP.NET 2.0 introduces a Web Part control that is designed to deal with the serialization, storage, and retrieval of customization and personalization data behind the scenes. In this article, the authors explain how you can put the WebPart control to work in your ASP.NET 2.0 applications.

Ted Pattison and Fritz Onion

MSDN Magazine September 2005

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend