【问题标题】:UI confirmation not firing the eventUI 确认未触发事件
【发布时间】:2011-02-13 18:37:12
【问题描述】:

我在我的 listView 中使用 jQuery 确认框,并在用户单击删除时显示确认框。 我面临的问题是,当用户单击“确定”时,不会触发 lvAlbums_ItemDeleting 事件。

下面是.aspx代码:

<link href="jQuery/jquery-ui.css" rel="stylesheet" type="text/css" />
    <link href="jQuery/jquery-ui-1.7.2.custom.css" rel="stylesheet" type="text/css" />
    <script src="https://www.google.com/jsapi?key=" type="text/javascript"></script>
    <script type="text/javascript">
        google.load("jquery", "1");
        google.load("jqueryui", "1");
    </script>
    <script type="text/javascript">
        $().ready(function () {
            $('#dialogContent').dialog({
                autoOpen: false,
                modal: true,
                title: "MySql Membership Config Tool",
                width: 300,
                height: 250
            });
        });

        function rowAction(uniqueID) {

            $('#dialogContent').dialog('option', 'buttons',
                {
                    "OK": function () { __doPostBack(uniqueID, ''); $(this).dialog("close"); },
                    "Cancel": function () { $(this).dialog("close"); }
                });

            $('#dialogContent').dialog('open');

            return false;
        }

</script>

</head>
<body>
    <form id="form1" runat="server">
    <div>
<div id="thumbs">
        <asp:ListView ID="lvAlbums" runat="server" GroupItemCount="15" DataKeyNames="album_id">
            <LayoutTemplate>
                <table id="groupPlaceholderContainer" runat="server" border="0" cellpadding="0" cellspacing="0"
                    style="border-collapse: collapse; width: 100%;">
                    <tr id="groupPlaceholder" runat="server">
                    </tr>
                </table>
            </LayoutTemplate>
            <GroupTemplate>
                <tr id="itemPlaceholderContainer" runat="server">
                    <td id="itemPlaceholder" runat="server">
                    </td>
                </tr>
            </GroupTemplate>
            <ItemTemplate>
                <div>
                    <asp:Image ID="Image1" runat="server" ImageUrl='<%# "ThumbNail.ashx?ImURL=/uploads/"+Eval("photo_file_name") %>'
                        Width="130" Height="150" BorderStyle="None" />
                    <asp:Label ID="lblPhotoTitle" runat="server" Text='<%# Eval("album_name") %>' CssClass="photoTitle"></asp:Label>
                    <br />
                    <asp:Button ID="btnDeleteAlbum" runat="server" Text="Delete Album" Width="144px" OnClick="lvAlbums_ItemDeleting" OnClientClick="javascript:return rowAction(this.name);" 
                        CommandName="Delete" />
                </div>
            </ItemTemplate>
        </asp:ListView>
    </div>
    <div class="pager">
        <asp:DataPager ID="DataPager1" runat="server" PagedControlID="lvAlbums" PageSize="12">
            <Fields>
                <asp:NextPreviousPagerField ShowFirstPageButton="true" ShowPreviousPageButton="true"
                    ShowLastPageButton="false" ShowNextPageButton="false" ButtonCssClass="first"
                    RenderNonBreakingSpacesBetweenControls="false" />
                <asp:NumericPagerField CurrentPageLabelCssClass="current" NextPreviousButtonCssClass="next"
                    NumericButtonCssClass="numeric" ButtonCount="10" NextPageText=">" PreviousPageText="<"
                    RenderNonBreakingSpacesBetweenControls="false" />
                <asp:NextPreviousPagerField ShowFirstPageButton="false" ShowPreviousPageButton="false"
                    ShowLastPageButton="true" ShowNextPageButton="true" ButtonCssClass="last" RenderNonBreakingSpacesBetweenControls="false" />
            </Fields>
        </asp:DataPager>
    </div>
    </div>

    <div id="dialogContent">
        <h3>confirm</h3>
        <p>Click ok to accept</p>
    </div>

    </form>

</body>

Firebug 抛出以下错误:

__doPostBack is not defined
[Break On This Error] "OK": function () { __doPostBa...ID, ''); $(this).dialog("close"); }, 

如果有人可以提供上述解决方案,将不胜感激。

我花了几天时间查看不同的 jQuery 确认框示例,但这是我能做的最好的。理想情况下,我希望在 gridviews、dataViews 和 ListViews 中使用http://jqueryui.com/demos/dialog/#modal-confirmation,但找不到确切提供要遵循的步骤的示例。

谢谢

【问题讨论】:

    标签: javascript jquery asp.net vb.net jquery-ui-dialog


    【解决方案1】:

    或者你可以使用这个:

        protected void Page_PreRender(object sender, EventArgs e)
        {
            //If the page doesn't have a control that causes a postback, __doPostBack() won't be output 
            //as a function definition. One way to override this is to include this line in your Page_PreRender():
    
            Page.ClientScript.GetPostBackEventReference(this, string.Empty);
            //This function returns a string calling __doPostBack(); but also forces the page to output 
            //the __doPostBack() function definition.              
        }
    

    【讨论】:

    • 我几乎可以肯定在 SO 上找到了这个,但我一辈子都找不到这个帖子。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-12-15
    • 2015-03-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-17
    • 1970-01-01
    相关资源
    最近更新 更多