i want to show a jQuery UI Dialog from Codebehind and need to refresh it after postbacks.
The dialog is a control to filter and find data. So the user selects from DropDownLists and enters text in TextBoxes, clicks a "Apply-Button", an asynchronous postback happens, the data gets filtered according to the user's selection and the result will be shown in a GridView. Therefore i need to update the UpdatePanel around the GridView.
The asynchronous postback works with help from these links:
- jQuery UI Dialog with ASP.NET button postback
- http://blog.roonga.com.au/2009/07/using-jquery-ui-dialog-with-aspnet-and.html
(Basically the dlg.parent().appendTo(jQuery("form:first"));
-Solution)
Problem: I cannot update the UpdatePanel neither with UpdateMode="Always" nor manually from codebehind via UpdatePanel.Update(). I assume that it has something to do with the Dialog not being inside of the UpdatePanel or something similar. Hopefully somebody can help me along.
Some source:
function createChargeFilterDialog() {
//setup dialog
$('#Dialog_ChargeFilter').dialog({
modal: true,
resizable: false,
autoOpen: false,
draggable: true,
hide: "Drop",
width: 850,
height: 600,
position: "center",
title: "Charge-Filter",
buttons: {
"Close": function () {
$(this).dialog("close");
}
},
open: function (type, data) {
$(this).parent().appendTo(jQuery("form:first"))
},
close: function (type, data) {
}
});
}
It gets called from codebehind when BtnShowDialog(outside the jQuery-Dialog) gets clicked via
AjaxControlToolkit.ToolkitScriptManager.RegisterStartupScript _
(Me.Page, GetType(Page), "showChargeFilterDialog", "createChargeFilterDialog();$('#Dialog_ChargeFilter').dialog('open');", True)
Update: i've also noticed a problem in the postback-values. All TextBoxes if empty or not have a comma appended. This indicates that controls are rendered multiple times according to: http://www.componentart.com/community/forums/t/60999.aspx
I'm sure that both issues are related. The whole dialog with all its controls will be recreated in every asynchronous postback, hence all control names exist multiple times in the DOM(causing the ViewState comma-appending issue). The controls are only visible in FireBug/IE Deveoper Toolbar and not in HTML-Source, hence i assume that jQuery causes these problems. How can i dispose the dialog or how can i prevent the recreation(check if already exists) of the dialog? Is this because the dialog is inside an UpdatePanel or because it's moved(via Javascript) outside the UpdatePanel?
Destroying the dialog before async postback doesn't solve the problem because the dialog will simply disappear:
<asp:Button ID="BtnApplyFilter" OnClientClick="$('#Dialog_ChargeFilter').dialog('destroy');" ... />
Your help is greatly appreciated.
Solution: i ended with using the ModalPopupExtender from the AjaxControlToolkit. After some small issues its working like a charm with asynchronous postbacks(don't forget to call MPE.Show()
in every code-behind function if you want the popup to stay visible). I could add more code if anybody is interested.