Nicholas Head

Filter by APML

Making jQuery UI’s Dialog Work With ASP.Net

by Nicholas Head 25. June 2009 22:06

You might have come across this problem in your travels, I know I have. Basically if you’re using jQuery UI’s Dialog and have a <form runat=”server”> inside of that dialog, your postback is not going to work. What’s going on?

jQuery UI is taking the dialog DIV content and moving it outside of the <form runat=”server”> tag. This makes your postback no longer function as expected.

Luckily we can fix this fairly easily with jQuery itself.

var dlg = $('#divMyDialog').dialog({
                    autoOpen: false,
                    modal: true,
                    width: 400,
                    resizable: false,
                    overlay: {
                        background: "black",
                        opacity: 0.5    
                    }
                });
dlg.parent().appendTo(jQuery('form:first'));

The special logic lies in the last line—using the reference to our created dialog, we get the parent container and move it back to the first <form> on the page. After that, all is well.

Bookmark and Share

Tags: ,

asp.net | jQuery

Are you moving or looking to move soon? Don't hurt your back shifting boxes around-- use HireAHelper to Book Movers Online!

Log in

Powered by BlogEngine.NET 1.6.1.0