开关箱不会触发 c# asp 净

标签: Asp.net jQuery C#
发布时间: 2017/2/25 3:29:46
注意事项: 本文中文内容可能为机器翻译,如要查看英文原文请点击上面连接.

我做了这个不会触发我想要的按钮的弹出。用户选择一个联系人,该联系人显示带有删除按钮,当单击,确认弹出窗口显示两个更多按钮,"Yes"和"否",他们不会触发出于某种原因。

ASPX:

<asp:Repeater runat="server" OnItemCommand="rptList_OnItemCommand" ID="rptList">
<HeaderTemplate>
    <table id="tblListContact">
        <tr id="tblRowContact">
            <th>
                <asp:Label runat="server" Text="TRNSLTName" />
            </th>
        </tr>
</HeaderTemplate>
<ItemTemplate>

<td>
    <asp:LinkButton runat="server" CommandName="selectContact" CommandArgument='<%# Eval("ID") %>'><%# Eval("Name") %></asp:LinkButton>
</td>
    <asp:LinkButton CssClass="deleteContact" ID="btnDelete" CommandName="deleteContact" CommandArgument='<%# Eval("ID") %>' runat="server" OnClientClick="return OpenPopup(this)">
    <asp:Image ImageUrl="Images/Icons/Deleted-16x16.png" ID="DeleteContact" runat="server" />
    </asp:LinkButton>
<div id="myModal" class="modal">
    <div class="modal-content">
        <h3 class="modalHdr">
            <asp:Label runat="server" Text="TRNSLTRemove users" /></h3>
        <p>
            <asp:Label runat="server" Text="TRNSLTDelete Contact"></asp:Label>
        </p>
            <asp:Button CommandName="noBtn" CommandArgument='<%# Eval("ID") %>' ID="ButtonNo" runat="server" Text="TRNSLTNo" CssClass="popupConfirm" />
            <asp:Button CommandName="yesBtn" CommandArgument='<%# Eval("ID") %>' ID="ButtonYes" runat="server" Text="TRNSLTYes" CssClass="popupConfirm" />
    </div>
</div>

</ItemTemplate>

C# 中︰

    /// <summary>
    /// Assigning commands to repeater.
    /// </summary>
    protected void rptList_OnItemCommand(object source, RepeaterCommandEventArgs e)
    {
        var contactId = Convert.ToInt64(e.CommandArgument);

        switch (e.CommandName)
        {
            case "selectContact":
                divRead.Visible = true;
                ContactId = contactId;
                var getContact = _ecSystem.GetContact(contactId);

                if (getContact != null)
                {
                    lblName.Text = getContact.Name;
                    lblPhone.Text = getContact.PhoneNumber;
                    lblMobile.Text = getContact.Cellphone;
                    lblAdress.Text = getContact.Street;
                    lblNotes.Text = getContact.Notes;
                    lblPage.Text = getContact.Homepage;
                    lblEmail.Text = getContact.Email;

                    imgPhone.Visible = !string.IsNullOrEmpty(lblPhone.Text);
                    imgMobile.Visible = !string.IsNullOrEmpty(lblMobile.Text);
                    imgAddress.Visible = !string.IsNullOrEmpty(lblAdress.Text);
                    imgNotes.Visible = !string.IsNullOrEmpty(lblNotes.Text);
                    imgPage.Visible = !string.IsNullOrEmpty(lblPage.Text);
                    imgEmail.Visible = !string.IsNullOrEmpty(lblEmail.Text);
                }
                break;

            case "deleteContact": //It never comes to these statements
                ContactId = contactId;
                break;

            case "noBtn": //It never comes to these statements
                break;

            case "yesBtn": //It never comes to these statements
                if (ContactId != null)
                {
                    _ecSystem.DeleteContact(ContactId.Value);
                }
                ContactId = null;
                Response.Redirect("Contact.aspx");
                break;

            case "editContact":
                divAdd.Visible = true;
                _editMode = true;
                var contacts = _ecSystem.GetContact(contactId);
                if (contacts != null)
                {
                    ViewState["Contacts"] = contacts;
                }
                break;
        }
    }

jQuery:

function OpenPopup($this) {
    if ($($this).attr("disabled") === "disabled") {
        return false;
    }
    var module = $($this).parent().find("#myModal");
    module.show();
    window.onclick = function (event) {
        if (event.target === module) {
            module.hide();
        }
    };

    return false;
}

解决方法 1:

你总是返回 falseOpenPopup 。因为您可以使用。

OnClientClick="return OpenPopup(this)"

将取消回发,如果你返回 falseOnClientClick 。相反你应该返回 true 如果您想要执行服务器单击。

function OpenPopup($this) {
    if ($($this).attr("disabled") === "disabled") {
        return false;
    }
    var module = $($this).parent().find("#myModal");
    module.show();
    window.onclick = function (event) {
        if (event.target === module) {
            module.hide();
        }
    };

    return true;
}

除了,你有一个错字,以下应该是相同的 CommandName :

<asp:LinkButton ID="btnDelete" CommandName="deleteContact" 

代码︰

case "deleteBtn"
官方微信
官方QQ群
31647020