开关盒不会触发c#asp net

时间:2017-01-17 09:53:07

标签: c# jquery asp.net

我制作了这个不会触发我想要的按钮的弹出窗口。用户选择联系人,联系人显示删除按钮,单击时,确认弹出窗口会显示另外两个按钮,"是"和#34;不",由于某种原因,它们不会触发。

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;
}

2 个答案:

答案 0 :(得分:2)

您始终从false返回OpenPopup。因为你使用。

OnClientClick="return OpenPopup(this)"

如果您从false返回OnClientClick,则会取消回发。相反,如果要执行服务器单击,则应返回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"

答案 1 :(得分:0)

在你的页面中有

CommandName="deleteContact"

并在开关

case "deleteBtn"

他们不匹配 在您的交换机中,您必须使用相同的CommandName

case "deleteContact"