Daniel Anderson Daniel Anderson - 6 months ago 15
jQuery Question

JQuery/ASP.NET Frustration

I am pulling my hair out trying to figure out why this code doesn't work!
I have a GridView control on an ASP.NET page, and that grid contains a link for editing each record as an ItemItemplate field. When clicked, a JQuery script executes to open a modal form for editing the record, and that works fine. I can add new records and edit existing ones.
The issue comes when I click the modal form's 'Close' button, which should trigger a refresh of the GridView to reflect the changes made. This is accomplished by having an ASP:Button that calls a DataBind event on the GridView.
The 'Close' event on the modal form fires, and I added a line to show the ClientID of the button to fire the event for, which works as it should. But the GridView DataBind never fires. I put a breakpoint on the btton's click event, but it never gets there. Any ideas? Here's the JQuery/JavaScript code I'm using in the form containing the GridView:

<script type="text/javascript">
$(document).ready(function () {
$('a.popup').live('click', function (e) {

var page = $(this).attr("href")

var $dialog = $('<div></div>')
.html('<iframe style="border:0px; " src = "' + page + '" width=600px" height="100%"></iframe>')
.dialog({
autoOpen: false,
modal: true,
appendTo:"form",
height: 550,
width: 'auto',
title: "Message Details",
buttons: {
"Close": function () { $dialog.dialog('close'); }
},
close: function (event, ui) {
alert('<%=btnRefresh.ClientID %>');
__doPostPack('<%= btnRefresh.ClientID %>', '');
}
});
$dialog.dialog('open');
e.preventDefault();
});
});
</script>


I've read a number of posts on something similar, but I can't seem to implement the right fix. The last thing I tried was adding the 'appendTo:"Form"' part suggested by someone in another post, but it doesn't change anything for me.
The btnRefresh code works fine. I just can't figure out how to make it fire when the user clicks the close button on the modal form.

Answer

I think it should be __doPostBack instead of __doPostPack.

You may also need to change ClientID to UniqueID as mentioned in the comments. The UniqueID also should be the name attribute of the button. something looking like this maybe: ctl00$btnRefresh.