views:

221

answers:

6

I need to load aspx page into jQuery UI's modal dialog window. I used following approach: load page content via ajax call into dialog's div and show it:

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

but I've got very strange error (IE8) in line 137215738 (!): 'theForm.elements.length' - is null or not an object. JS debbuger says that source code is not available for such location. I have an assumption that this error happens because of multiple 'form' tags that appears on page after ajax call

I wonder, how can i fix this? Or maybe some other way of showing aspx page in modal dialog?

+3  A: 

You cannot fully embed one ASPX page's content within another for a couple of reasons:

  1. You would be nesting <html> tags in a non-sensical way.
  2. You are polluting one page's javascript state with the other's.

You need to render Page.aspx as a partail view, rather than including the entire payload of an ASPX page.

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

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

John Gietzen
+4  A: 

What about putting an IFRAME in the modal, and setting the IFRAME src to Page.aspx?

slolife
A: 

Solved by creating generic HTTP handler and writing to the response only nessesary html markup.

kilonet
how did you do? please share you code i am looking after it.
Abu Hamzah
+1  A: 

right click on your web project in Visual Studio and add 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');
});
kilonet
A: 

Please can you explain more? i am getting the same error, but i didn't understand your Http handler technique.

waqar ali
A: 

there you go ...

Andreas Niedermair