1

I created two similar visual web parts (one lists top 10 "popular-content" items, another top 10 "new content" items) with ajax support. For querying data from list (in both wparts) I use similar linq query. Both web parts work OK if I put them separately on different pages, but if I put them on same page I got error

"Attempted to use an object that has ceased to exist. (Exception from HRESULT: 0x80030102 (STG_E_REVERTED))"

Problem: Web parts work separately OK but together they won't (first wp added to page work, but adding second generates error).

Please any suggestion?

p.s. Update panels have different names, also as timer controls which are used to enable ajax functionality (I assume this shouldn't be a problem)

2 Answers 2

4

Are you disposing of an SPWeb or SPSite obtained from the current SPContext in your logic?

4
  • both web parts have their own logic defined as shown below using (SPWeb web = SPContext.Current.Web) { linq query; gridview binding; }
    – trip
    Aug 22, 2011 at 10:04
  • 2
    "Well there's your problem". If you dispose of the Context, it's not available at all again until the page is reloaded. Use new SPSite(SPContext.Current.Site.Url) instead.
    – James Love
    Aug 22, 2011 at 10:15
  • only if you create your objects yourself, do you get to dispose them. Read this guidance from MSDN to clarify msdn.microsoft.com/en-us/library/ee557362(v=office.14).aspx Aug 22, 2011 at 10:54
  • James - You were right. After modification,everything seems ok. Thank you!!! @Anders - Thanx, I will read guidance.
    – trip
    Aug 22, 2011 at 13:04
0

I agree with James Love and don't dispose of the current context's spweb and spsite objects. But you might also run into this another problem with multiple update panels on the page. Did you implement anything to handle this?

I had to use Sys.WebForms.PageRequestManager.getInstance() in javasript and check if an update was already in progress and if so, queue the update panel request until the first one returns. I used code similar to the code below to fix this issue.

var _callQueue = new Array(); 
var _executingElement = null; 
var _prm = Sys.WebForms.PageRequestManager.getInstance(); 
_prm.add_initializeRequest(initializeRequest);
_prm.add_endRequest(endRequest); 
function initializeRequest(sender, args) { if (_executingElement != null) { var postBackElement = args.get_postBackElement(); if (_executingElement != postBackElement.id) { args.set_cancel(true); Array.enqueue(_callQueue, postBackElement.id); } } }
function endRequest(sender, args) { _executingElement = null; while (_callQueue.length > 0) { var elements = Array.dequeue(_callQueue); var webpart = document.getElementById(elements[1]); if (webpart != null) { var progress = document.getElementById(elements[2]); if (progress != null && progress.style != null) { progress.style.display = 'none'; } if (webpart != null && webpart.style != null) { webpart.style.display = 'block'; } } else { _executingElement = elements[0]; setTimeout("__doPostBack('" + _executingElement + "', '')",0); return; } } } 
2
  • I also use PageRequestManager. But for now I don't have any problems with update panels. All are async, and it seems that everything is ok (I have scriptmanager defined in master page, maybe that is a difference between our web parts)
    – trip
    Aug 22, 2011 at 13:08
  • Ok, good. I also have script manager on the master. This was a few years go for SP 2007 so maybe something has changed. Thanks! Aug 22, 2011 at 13:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.