1

我正在使用 VS 2012/ASP.NET(网络表单)4.5。我有一个带有传统用户控件的页面:

<%@ Page Title="" Language="C#" MasterPageFile="~/ControlCenter/MasterAdmin.master" AutoEventWireup="true" CodeFile="OrderDetail.aspx.cs" Inherits="ControlCenter_OrderDetail" %>

<%@ register src="~/Controls/OrderDetailMenu.ascx" tagprefix="eoi" tagname="OrderDetailMenu" %>

<asp:content ID="OrderDetailHead" ContentPlaceHolderID="head" Runat="Server">
<link rel="stylesheet" href="http://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css" />
<script type="text/javascript" src="../Scripts/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="../Scripts/jquery-ui-1.8.20.js"></script>
</asp:content>
<asp:content ID="OrderDetailBody" ContentPlaceHolderID="BodyContent" Runat="Server">
<table style="width: 100%;">
    <tr>
        <td colspan="4">
            <eoi:orderdetailmenu id="OrderDetailMenu" runat="server" />
        </td>
    </tr>
..............

在控件内部,我使用 jQuery 对话框来显示嵌套的用户控件:

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="OrderDetailMenu.ascx.cs" Inherits="Controls_OrderDetailMenu" %>
<%@ register src="~/Controls/UserComments.ascx" tagprefix="eoi" tagname="UserComments" %>
<%@ register src="~/Controls/OrderComments.ascx" tagprefix="eoi" tagname="OrderComments" %>

<script type="text/javascript">
$(document).ready(function()
{
    //init dialog
    $("#userCommentsPanel").dialog({
        title: "Add User Comment",
        height: 300,
        width: 700,
        autoOpen: false,
        show: "puff",
        hide: "puff", 
        buttons: [
            {
                text: "Close Window",
                click: function()
                {
                    $(this).dialog("close");
                }
            }
        ]
    });

    //popup link event
    $("#addUserCommentsLink").click(function(e)
    {
        $("#userCommentsPanel").dialog("open");
        e.preventDefault();
        return false;
    });
});
</script>
<table border="0" cellpadding="2" cellspacing="3">
<tr>
    <td>
        <a href="#" id="addUserCommentsLink" name="addUserCommentsLink">
            Add User Comment
        </a>
    </td>
</tr>
</table>
<asp:panel id="userCommentsPanel" clientidmode="Static" runat="server">
<div class="userCommentsPopup">
    <eoi:usercomments id="UserComments" runat="server" />
</div>
</asp:panel>

嵌套控件内部是简单的表单,如下所示:

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="UserComments.ascx.cs" Inherits="Controls_UserComments" %>
<table style="width:100%;" id="userCommentsFormTable" runat="server">
<tr>
    <td width="1%">&nbsp;</td>
    <td>&nbsp;</td>
</tr>
<tr>
    <td colspan="2">
        <asp:validationsummary id="userCommentsSummary" runat="server" cssclass="validation" ShowModelStateErrors="true" />
    </td>
</tr>
<tr>
    <td>
        <asp:textbox id="commentsBox" runat="server" columns="80" rows="5" textmode="MultiLine"></asp:textbox>
    </td>
    <td>&nbsp;</td>
</tr>
<tr>
    <td align="right">
        <asp:button id="commentsButton" runat="server" text="Save" onclick="commentsButton_Click" />
    </td>
    <td>&nbsp;</td>
</tr>
</table>

...事件处理程序:

    protected void commentsButton_Click(object sender, EventArgs e)
{
        //this method is never executed. :(
}

Page_Load 触发,但按钮单击事件没有......根本没有发生任何事情。这里发生了什么事?断点也不会被击中。就好像事件什么都不做。我确定这与页面生命周期的丑陋有关,但我无法在 Googleland 中找到解决方法。

谢谢!

4

1 回答 1

0

我终于在这里找到了解决方案:

jQuery UI 对话框(模态),防止任何回发

只需在对话框声明之后添加这行神秘的代码:

$("#userCommentsPanel").parent().appendTo(jQuery("form:first"));

...它只是工作。

于 2013-04-16T23:25:45.663 回答