Generic Dialogs

Generic Dialogs


Hello,
imagine a dialog frame without any content but assigned buttons and
all the stuff. This dialog is created using the $.dialog(...) method
and hidden by default. If someone clicks a special link an ajax
request is made to fetch some content, the content will be pushed into
the dialog (using the html() method) and the dialog will be opened.
I implemented this functionality and it works very well for me.
Now imagine a step further: The content from the ajax request contains
a link that will create another dialog with some form elements. (the
dialog HTML div is defined only once at the bottom of the ajax
generated content) The creation of this second dialog will be
performed from scratch every time and the new dialog will
automatically open (by using the autoOpen property). If the dialog
gets closed it will be destroyed (using dialog('destroy')).
Now my problem:
If I refresh the hole page using the browser refresh button everything
works well - I open the first level dialog, the ajax generated content
gets inserted (and so the dialog div of the second level dialog too)
and the second level dialog opens and behaves correctly. If I
reproduce the same scenario the dialogs will open up correctly too but
the form (inside the second level dialog) won't work because I cannot
address the form elements by ID anymore. It seems if the second
attempt to create the content using an ajax call leaves some elements
created by the jQuery Dialog UI component that aren't cleaned up on
destroying the dialog.
Can someone help me on this?
Regards.