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.

Tags: ,

asp.net | jQuery

Comments

7/16/2009 2:15:16 PM #

Tim Santeford

You just saved my life today. I knew this needed to be done but the ''form:first'' selector was the key, thanks a million. Now I need to be able to have the dialog load another aspx page through ajax and then wire up its postsbacks to only submit inside the dialog and not redirect the parent page. Any thoughts on that?

Tim Santeford United States | Reply

7/16/2009 2:42:41 PM #

Nicholas

Tim,

There's no easy way to do that off the top of my head.. what I've done in the past is stuck an <iframe> inside of the jQuery UI Dialog, kinda cheated a bit.

Nicholas United States | Reply

8/6/2009 10:48:44 PM #

Hasika Mahindaratha

Thnaks for the solution... You just saved my life today.

Hasika Mahindaratha Sri Lanka | Reply

1/23/2010 4:17:30 AM #

Salman Farsi

Thanks a lot, to make my life easier...

Regards

Salman Farsi United States | Reply

Add comment


(Will show your Gravatar icon)

  Country flag

biuquote
  • Comment
  • Preview
Loading




Log in

Powered by BlogEngine.NET 1.6.0.0