简体   繁体   English

jQuery / ASP.NET失败

[英]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. 我在ASP.NET页上有一个GridView控件,该网格包含一个链接,用于将每个记录编辑为ItemItemplate字段。 When clicked, a JQuery script executes to open a modal form for editing the record, and that works fine. 单击时,将执行JQuery脚本以打开用于编辑记录的模式表单,并且效果很好。 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. 当我单击模式窗体的“关闭”按钮时,就会出现问题,这应该触发GridView的刷新以反映所做的更改。 This is accomplished by having an ASP:Button that calls a DataBind event on the GridView. 这可以通过在GridView上使用一个ASP:Button来调用DataBind事件来实现。 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. 触发模式窗体上的“关闭”事件,我添加了一行以显示为其触发事件的按钮的ClientID,该行应能正常工作。 But the GridView DataBind never fires. 但是GridView DataBind永远不会触发。 I put a breakpoint on the btton's click event, but it never gets there. 我在btton的click事件上设置了一个断点,但它从未到达终点。 Any ideas? 有任何想法吗? Here's the JQuery/JavaScript code I'm using in the form containing the GridView: 这是我在包含GridView的表单中使用的JQuery / JavaScript代码:

<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. 我尝试的最后一件事是在另一篇文章中添加某人建议的“ appendTo:“ Form”部分,但这对我没有任何改变。 The btnRefresh code works fine. btnRefresh代码可以正常工作。 I just can't figure out how to make it fire when the user clicks the close button on the modal form. 我只是不知道当用户单击模式窗体上的关闭按钮时如何使其触发。

I think it should be __doPostBack instead of __doPostPack . 我认为应该是__doPostBack而不是__doPostPack

You may also need to change ClientID to UniqueID as mentioned in the comments. 如注释中所述,您可能还需要将ClientID更改为UniqueID The UniqueID also should be the name attribute of the button. UniqueID也应该是按钮的name属性。 something looking like this maybe: ctl00$btnRefresh . 看起来像这样的东西: ctl00$btnRefresh

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM