简体   繁体   English

开关盒不触发C#ASP网络

[英]Switch case does not trigger c# asp net

I made this popup that does not trigger the button I want it to. 我做了这个弹出窗口,它不会触发我想要它的按钮。 The user selects a contact, the contact is displayed with a delete button, when clicked, the confirmation popup appears with two more buttons, "Yes" and "No", they do not trigger for some reason. 用户选择一个联系人,该联系人会显示一个删除按钮,单击该联系人会显示确认弹出窗口,并显示另外两个按钮“是”和“否”,由于某种原因它们不会触发。

ASPX: 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#: 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: 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;
}

You always return false from OpenPopup . 您总是从OpenPopup返回false Since you use. 自从你用。

OnClientClick="return OpenPopup(this)"

The postback will be canceled if you return false from OnClientClick . 如果从OnClientClick返回false ,则回发将被取消。 Instead you should return true if you want to perform the server-click. 相反,如果要执行服务器单击,则应返回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;
}

Apart from that you have a typo, following should be the same CommandName : 除此之外,您还有一个错字,以下应该是相同的CommandName

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

Code: 码:

case "deleteBtn"

In your page you have 在您的页面中

CommandName="deleteContact"

and in switch 并在开关中

case "deleteBtn"

they not match in your switch you must use the same CommandName 它们在您的交换机中不匹配,您必须使用相同的CommandName

case "deleteContact"

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

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