Showing posts with label portal. Show all posts
Showing posts with label portal. Show all posts

Wednesday, March 21, 2012

Trying to implement a thread queue for page with 6 update panels

I am attempting to write a FIFO thread queue for the dashboard portion of a portal application. There are 6 update panels that refresh independent of each other about every 60 seconds, so there are a lot of postback collisions and I need something to save postbacks and re-issue them when the callback from the prior async call is returned.

It looks like there has been quite a bit of effort put into this, but none of the code I could locate would work in my situation because of various "can't find id", "null reference", and "object does not have this function" -related js errors.

Here is what I have so far:
Sys.Application.add_load(ApplicationLoadHandler)

function ApplicationLoadHandler(sender, args)
{
var prm = Sys.WebForms.PageRequestManager.getInstance();
if (!prm.get_isInAsyncPostBack())
{
prm.add_initializeRequest(InitializeRequest);
prm.add_endRequest(CompleteRequest);
}
}
// initialize a queue
var myQueue = new Array();

function CompleteRequest(sender, args)
{
if(myQueue.length > 0)
{// fire correspond event again of the item cached
var control = $get(myQueue[0]);
setTimeout('__doPostBack(\'' + control.id + '\',\'\')', 0);
Array.removeAt(myQueue, 0);
}
}
function InitializeRequest(sender, args)
{
var prm = Sys.WebForms.PageRequestManager.getInstance();

if (prm.get_isInAsyncPostBack())
{
// if it's working on another request, cache the current item that cause the request
args.set_cancel(true);
Array.add(myQueue, args.get_postBackElement().id);
}
}

if(typeof(Sys) !== "undefined") Sys.Application.notifyScriptLoaded();

Even if this did work, it wouldn't do what I want it to do because '__doPostBack(\'' + control.id + '\',\'\' would strip out all of the eventargs that were sent along with my postback (for instance, if the user initiated the postback via mouse click) and turn "doPostBack('gridviewSomething', 'Select$1')" into "doPostBack('gridviewSomething')", which is clearly no good.

This code will properly interrupt postbacks and save them to queue, but upon callback and re-initiation I get problems. Anyone have any suggestions? I feel like this is so close and I am loosing my hair over it, so help is much appreciated.

Merry (early) Christmas.

http://disturbedbuddha.wordpress.com/2007/12/12/handling-multiple-asynchronous-postbacks/

Trying to open a new browser window from within an UpdatePanel and getting Sys.WebForms.Pa

I'm in the process of developing a module for a DotNetNuke portal site. The module hosts an ASP2.0 Wizard control which guides the user through report & parameter selection & then when the Finish button is clicked the module opens a new browser window at a url which hosts the ASP2.0 ReportViewer control.

This all worked OK until I enable AJAX on the site. I've wrapped the Wizard control in an UpdatePanel and although the functionality of the wizard is fine when the Finish button is clicked I get the error"Sys.WebForms.PageRequestManagerParserErrorException: The message from the server could not be parsed. Common causes for this error are when the response is modified by calls to Response.Write(), response filters, HttpModules, or server trace is enabled."


The wizard_FinishButtonClick handler is doing some housekeeping then calling Response.Write() with a JavaScript string to open the new browser window so I'm guilty as charged. I've tried using DNN's Intermodule Communications to get another module to kick off the browser open but I still end up with the same exception. What would be the best way of getting around this issue ?


ThanksScott

The Wizard control is not supported by Ajax... along with a few other controls... You can work around it by wrapping your Wizard into a Iframe but not within a update panel...


To nitpick, the Wizard controlis supported within an UpdatePanelas long asits contents are converted to an editable template.

Seehttp://ajax.asp.net/docs/overview/UpdatePanelOverview.aspx#UpdatePanelCompatibleControls.


Thanks for your responses guys but I don't think the interaction of the Wizard and UpdatePanel is the issue.

The reason the wizard was wrapped by an UpdatePanel was that

1) the wizard is wrapped by a Drag panel and a collapsible panel. The functionality of the Drag & Collapse panels works fine but any activity within the wizard generates a postback that resulted in the whole thing being relocated back to it's initial start point.

2) I then added the UpdatePanel and I can now move the panel around the page and do stuff within the wizard without it relocating to start point.

3) It was at this point that I started to get the error which is caused by the Response.Write when the wizard Finish button is clicked. There is another method called when the Finish button is clicked and this functionality still works it's just the Response.Write I need to avoid.

I'll be more specific this time - is there a way to open a new browser within an update panel ?

Regards
Scott


Well it seems it is possible to do this. All I had to do was use the script manager to register a client script block from the Finish button click event handler.

the code for this would be for example

protected void wizReport_FinishButtonClick(object sender, WizardNavigationEventArgs e)
{
try
{
string reportViewerUrl = System.Configuration.ConfigurationManager.AppSettings["ReportViewerUrl"].ToString();
System.Type cstype = typeof(class name);
string csname = "PopUpReport";
string script = @."window.open('" + reportViewerUrl + "','_blank','location=no,scrollbars=yes,resizable=yes,top=0,left=0,height=800,width=950');";
ScriptManager.RegisterClientScriptBlock(wizReport, cstype, csname, script, true);
}
catch (Exception x)
{
string s = x.Message;
}
}