Using an ajax:ModalPopup Without a TargetControl

The ModalPopup extender usually requires a control for firing up, set through the TargetControlID property. However, sometimes you may want to show and hide the panel programmatically. All you need is a fake activator, like the following: The Extender <ajax:ModalPopupExtender ID="mpeInfo" runat="server" TargetControlID="divFakeActivator" PopupControlID="pnlInfo" CancelControlID="bttInfoClose" /> The Panel <asp:Panel ID="pnlInfo" runat="server"> Hello World!!! </asp:Panel> The C# code // Show and hide programmatically mpeInfo.Show(); mpeInfo.Hide(); Note (2025): This post reflects an older ASP.NET AJAX pattern. In modern frameworks you would likely manage modal dialogs through client‑side libraries (e.g., Bootstrap, React, Blazor components). ...

September 25, 2007 · 1 min · Andrea Azzola

Issues With AJAX and a Custom HttpModule

My web app needs to catch every non‑existent path as a search string, because I’m implementing an HttpModule that handles URLs in an SEO‑friendly way, e.g.: http://contoso.com/search-string But the Microsoft AJAX ScriptModule interfered, causing runtime errors like “AJAX Framework failed to load…”. The fix was to register my module after the ScriptModule and selectively bypass AJAX requests. <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, ..." /> <add name="MyModule" type="MyModule" /> using System; using System.Linq; using System.Web; public class MyModule : IHttpModule { public void Init(HttpApplication context) { context.PostResolveRequestCache += Application_OnAfterProcess; } private void Application_OnAfterProcess(object source, EventArgs e) { var application = (HttpApplication)source; var context = application.Context; if (context.Request.Headers["x-microsoftajax"] == null) { if (!System.IO.File.Exists(application.Request.PhysicalPath) && !application.Request.Url.ToString().Contains(".axd") && !application.Request.Url.ToString().Contains(".asmx")) { string newUrl = "~/Search.aspx?q=" + context.Server.UrlEncode(application.Request.Url.Segments.Last()); // other logic here… context.RewritePath(newUrl); } } } public void Dispose() { } } This runs at PostResolveRequestCache and, when the special x-microsoftajax header is absent, it rewrites unknown paths to your search page while letting AJAX handlers (*.axd, *.asmx) pass through normally. ...

June 18, 2005 · 1 min · Andrea Azzola