ASP.NET + jQuery UI Modal: load an aspx page into a modal dialog

I need to load an aspx page into a jQuery modal dialog box. I used the following approach: load the contents of the page using an ajax call in the div dialog and show it:

$.get('Page.aspx', function(response){ $('#dialog').html(response); $("#dialog").dialog('open'); }); 

but I have a very strange error (IE8) on line 137215738 (!): 'theForm.elements.length' is null or not an object. JS debbuger says the source code is not available at that location. I have an assumption that this error is due to several form tags that appear on the page after an ajax call

I wonder how can I fix this? Or maybe some other way to show an aspx page in a modal dialog?

+4
source share
4 answers

You cannot completely embed one content of an ASPX page in another for several reasons:

  • You can embed <html> tags in a non-sensitive way.
  • You are polluting one javascript state of one page with others.

You need to display Page.aspx as a Page.aspx view, and not include all the payload on the ASPX page.

I am not 100% sure if you can do this in plain-old-asp.net without calling the Render function for individual controls, using the Response stream as the target.

In ASP.NET-MVC, however, you can use the result of PartialView.

+3
source

What about entering IFRAME in modal mode and setting IFRAME src to the .aspx page?

+6
source

right-click on your web project in Visual Studio and add a new generic HTTP handler. The code will look like this:

DialogContentHandler.ashx:

  public class DialogContentHandler: IHttpHandler { public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; string s = getDialogContent(); context.Response.Write(s); } public bool IsReusable { get { return true; } } } 

aspx code:

 $.get('DialogContentHandler.ashx', function(response){ $('#dialog').html(response); $("#dialog").dialog('open'); }); 
+2
source

Solved by creating a common HTTP handler and writing back only the necessary html markup.

0
source

Source: https://habr.com/ru/post/1301206/


All Articles