I have an UpdatePanel on a page, and within the UpdatePanel are a GridView and a Button that updates the GridView when clicked. I click the Button, a couple of seconds later the asynch callback returns and the GridView is re-rendered on the screen. Great. Now, what I would like to do is hook into the beginRequest and endRequest events of the client-side PageRequestManager and add a couple of functions that will replace the inner html of whatever UpdatePanel is making the callback request with a "Please Wait..." message while the callback is processing so that the user cannot change anything within the UpdatePanel until the callback is finished. What I can't figure out how to do is get a client-side reference to the UpdatePanel that initiated the current ajax callback. The UpdateProgress control is very close to what I'm trying to achieve, except that it doesn't "hide" its associated UpdatePanel.
Anybody have any ideas?
My recommendation would be to use the UpdateProgress control, and style it such that it covers the UpdatePanel. That would be easiest.
If you want to go ahead and hook beginRequest/endRequest, to answer your question about determining which UpdatePanel contains the control causing the postback, take a look at the JavaScript behind the UpdateProgress control, specifically this function:
function Sys$UI$_UpdateProgress$_handleBeginRequest(sender, arg) { var curElem = arg.get_postBackElement(); var showProgress = !this._associatedUpdatePanelId; while (!showProgress && curElem) { if (curElem.id && this._associatedUpdatePanelId === curElem.id) { showProgress = true; } curElem = curElem.parentNode; } if (showProgress) { this._timerCookie = window.setTimeout(this._startDelegate, this._displayAfter); } }
Hai,
can u plz tell me any other sample.Me too facing same prblm...
Does this help?
http://weblogs.asp.net/rajbk/archive/2007/01/08/using-the-updateprogress-control-as-a-modal-overlay.aspx
Thanks for the suggestion Steve. In case anybody else is interested in doing something similar, here's the code for a simple extension of the UpdatePanel class that implements Steve's approach to the problem I originally described:
using System;using System.Collections.Generic;using System.Text;using System.Web;using System.Web.UI;namespace CustomAjaxControls{public class MyUpdatePanel : UpdatePanel{public MyUpdatePanel():base(){this.Load +=new EventHandler(MyUpdatePanel_Load);}private void MyUpdatePanel_Load(object sender, EventArgs e){RegisterClientScripts();}private void RegisterClientScripts(){StringBuilder library =new StringBuilder("");// start-up script (registered once for each instance of MyUpdatePanel on the page)this.Page.ClientScript.RegisterStartupScript(typeof(MyUpdatePanel),"StartUp" +this.UniqueID,"new MyUpdatePanel('" +this.ClientID +"');",true);// function library (registered once for all instances of MyUpdatePanel)library.AppendLine("// MyUpdatePanel javascript class");library.AppendLine("function MyUpdatePanel(panelId)");library.AppendLine("{");library.AppendLine("// properties");library.AppendLine("var _panel = document.getElementById(panelId);");library.AppendLine();library.AppendLine("// methods");library.AppendLine("this._handleBeginRequest = MyUpdatePanel_handleBeginRequest;");library.AppendLine();library.AppendLine("// hook into system events");library.AppendLine("Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(this._handleBeginRequest);");library.AppendLine();library.AppendLine("// MyUpdatePanel methods");library.AppendLine("function MyUpdatePanel_handleBeginRequest(sender, args)");library.AppendLine("{");library.AppendLine("var elem = args.get_postBackElement();");library.AppendLine();library.AppendLine("// find out if the object that requested the callback is our MyUpdatePanel");library.AppendLine("while (elem)");library.AppendLine("{");library.AppendLine("if (elem == _panel)");library.AppendLine("{");library.AppendLine("// hide the contents of the MyUpdatePanel until the asynchronrous callback returns");library.AppendLine("_panel.innerHTML ='Updating...';");library.AppendLine("return;");library.AppendLine("}");library.AppendLine("elem = elem.parentNode;");library.AppendLine("}");library.AppendLine("}");library.AppendLine("}// end class MyUpdatePanel");library.AppendLine();this.Page.ClientScript.RegisterClientScriptBlock(typeof(MyUpdatePanel),"library", library.ToString(),true);}}}
No comments:
Post a Comment