Sharepoint Forum

Ask Question   UnAnswered
Home » Forum » Sharepoint       RSS Feeds

Webpart - An Error has occurred

  Asked By: Caitlin    Date: May 17    Category: Sharepoint    Views: 10899

i have built a webpart that iterates through all the sites in the VirtualServer and retrieves all documents, announcements and events posted within the last 7 days. I use a 3 datagrids for displaying each. the webpart works fine when i preview it from the Webpart gallery

but when i try to add it to a webpart page, the webpart is not added to the page. In the webpart pane an error is displayed at the top "An error has occurred".

Anyone can tell me what could be the problem? Anyone has faced this problem. Since it is not being loaded on the page i am not able to debug. Since it is working fine when i preview it debugging is of no use...

any help would be great



11 Answers Found

Answer #1    Answered By: Cheryl Kelley     Answered On: May 17

How are you previewing it if you can't load it on the page?

It could be one of several problems, and I might miss some but I'm sure others will chime in and cover the ones I miss.

Make sure you have the class/webpart registered as a safe part in the web.config file.
The type/class name in your DWP file matches your web part.
I like to use stsadmin to add  the web part packages to the server, it handles quite a bit for you and lets you know if there's something wrong when you install it.

Answer #2    Answered By: Sharonda Mcfarland     Answered On: May 17

Yes the webpart  is registered safe. I always use stsadm to deploy my webparts. Then i add  it to the Webpart Gallery. You can preview  a webpart by clicking on it from the webpart gallery. The only drawback is that dropdown, button click events  will not fire. But I have no button click events in my webpart just onload.

The update on yesterdays status is that after I made some changes to the code. Now the webpart does not work both in preview and page. When i try to debug, it enters the onload no errors (all methods properly enclosed in try catch) retrieves all data. Enters CreateChildControls. I bind the data to each datagrid in the each datagrid's onload. again no errors. nothing was caught in the try catch block. but after exiting CreateChildControls and before entering RenderWebpart something happens and i am shown "An unexpected exception operation occurred".

I am totally clueless here. i have developed my fair share of webparts. I know sharepoint on some days  can make you look really silly.

Initially there were three webparts for listing the latest documents, announcements  and events. Since each webpart was iterating through all the wss sites  under the virtual server, it was slowing the page  considerably. These webparts are still working. I thought I will merge them all together and get all info in one iteration and display them. Thats when al the problem  started.

Any ideas on where/what i am overlooking would be of real help.

Answer #3    Answered By: Damon Garner     Answered On: May 17

A few things about events  and webparts.

If you have events tied to anything that has data, if you change the data on anything that is trying to fire an event it will cause the event to be not fired. In other words if you have a combo box with 6 items, if you have it set to postback and try to capture the SelectedIndexChanged event if you don't populate the combo with the exact same values, the event will be discarded.

I'm not sure what you are referring too when you say that you are using STSAdm to deploy your webparts the add  it to the web part gallery. Are you using 'Addwppack' or doing something else. When I add a webpart  using STSAdm it's already in the web part gallery, I don't have to take any other steps to make it show up there.

As for previewing the web part by clicking on it in the webpart gallery, I'm still not clear on what you mean by 'preview'. If you click on it in the gallery, until you actually add it to a page  it's not being rendered anywhere. Are you actually seeing the part displayed  on your page?

One last question are you using ASP.Net 2.0 to make your webparts?

When I get to work tomorrow I'll double check my notes about the order of events firing and post when events actually are getting fired, and what other methods are called between CreateChildControls and RenderWebPart.

Answer #4    Answered By: Christop Mcfadden     Answered On: May 17

i do stsadm -o addwppack -filename <cabfilename> -globalinstall -force
Web Part gallery  (copied from MSDN online)

Make a Web Part available in the Web Part gallery


On a top-level Web site, click Site Settings.


Under Administration, click Go to Site Administration.


Under Site Collection Galleries, click Manage Web Part gallery.


On the Web Part Gallery page, click New Web Part.


Select the check box next to the Web Parts you want to include in the gallery, and then click Populate Gallery.

when you go to the Web Part gallery mentioned above. you can click on the webpart  dwp file name. Then in the WPPreview.aspx (i am not sure if it is WPPrev or WPPreview) your webpart will be rendered. The advantage in this is that this page  catches all errors and displays them to you (if you forgot to catch something this page will do it for you).

If you mean to ask if i am using .Net Framework 2.0 no i am still using .Net Framework 1.1

Answer #5    Answered By: Victoria Bell     Answered On: May 17

Ok, I never have used that, I think that I said the wrong thing when I described how I add  web parts to the site. I use STSadmWin which gives you a nice GUI to perform tasks on a site. It does all the plumbing for you when deploying a web part. You can do a search for it on Google and you can get the latest version to download. I started using this after the class I took through Mindsharp and it really helps to make sure that when performing tasks you don't miss any of the steps (which SharePoint has quite a few quirks and steps to take).

Have you tried attaching to the IIS worker process from visual studio to debug  your web part?

Answer #6    Answered By: Cassidy Sharpe     Answered On: May 17

Just a quick guess… What is happening is the data grid is likely rendering itself. Have you tried pulling your code out and testing it as a web control? It sounds like something in the parameters for the data grid.

Answer #7    Answered By: Peter Peterson     Answered On: May 17

I too thought it must be data grid parameters, but if that is the problem  the error  would occur when you call datagrid.RenderControl(output). but when i am debugging  the thread does not enter the RenderWebpart method. anyway i will try your suggestion of doing it from a web control.

I thought of two things.

i have exposed bool properties to display the datagrid like this
public bool ShowDatagrid
get { return datagrid.Visible;}
set { datagrid.Visible = value;}
would this cause any problem? I just wanted to avoid using a boolean datamember and then do an if(booldatamember)

if the control is not visible, it does not render

the other thing is i have somehow screwed the table, tr, td structure of the webpart....

Answer #8    Answered By: Hans Weiss     Answered On: May 17

The addwppack operation that you are using can place the Web Part(s)
from the CAB directly into the Virtual Server Gallery if the manifest
indicates that there is a DWP file to deploy. This is the default in the
VS.NET template so that is probably why people are confused about you
manually adding it to the Site Collection Web Part Gallery for

Secondly, you are doing a globalinstall. This means that your assembly
will be deployed to the GAC. You must do a deployment after every code
change and you must run iisreset after every deployment. I don't think
that you can debug  a Web Part running in the GAC.

So, I would suggest not doing a globalinstall. You will need to run the
deletewppack operation and then run addwppack so that your assembly will
be in the bin of your IIS Web Site's home directory. Be sure that the
PDB is also in the bin directory. Then try debugging  again.

If debugging still fails, perhaps some trace statements would be

Without your code and an error  message like: "An unexpected exception
operation occurred", I'm not sure how much more help  we can be. We'd all
be guessing and/or grasping at straws.

Answer #9    Answered By: Alison West     Answered On: May 17

The problem  wouldn’t necessarily occur if you call RenderControl. There are differences between the way a control is rendered when it is attached to a control tree and the way that it renders with RenderControl.

Taking the code out of SharePoint, testing it, and putting it back will have the greatest possibility of success. You can attach to the SPS process to debug  as well, but there are still a lot of moving pieces in SharePoint that you have to pay attention to.

Answer #10    Answered By: Freddy Heath     Answered On: May 17

managed to find the cause of the problem  it was a typo in the dwp file...

i had changed the namespace of the webpart  assembly and must have made the mistake effecting the change in the dwp file

But, the error  messages
"Unexpected operation occurred"
"Object reference not set to an instance of the object"
"An error has occurred"
do not in any way give you a clue to the actual problem

Answer #11    Answered By: Joanna Dixon     Answered On: May 17

No problem, get used to that error  message, it's about the only one you'll ever get.

Didn't find what you were looking for? Find more on Webpart - An Error has occurred Or get search suggestion and latest updates.