0

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:

<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;
}
10
  • There are typos in your CommandNames, f.e.it's deleteContact Commented Jan 17, 2017 at 9:58
  • So where should I change? Commented Jan 17, 2017 at 10:01
  • 1
    well, they should be the same Commented Jan 17, 2017 at 10:02
  • Can you create a post and explain? Commented Jan 17, 2017 at 10:05
  • Isn't it obvious? ASPX: <asp:LinkButton ID="btnDelete" CommandName="deleteContact"... Code: case "deleteBtn". Commented Jan 17, 2017 at 10:15

2 Answers 2

2

You always return false from OpenPopup. Since you use.

OnClientClick="return OpenPopup(this)"

The postback will be canceled if you return false from OnClientClick. Instead you should return true if you want to perform the server-click.

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:

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

Code:

case "deleteBtn"
Sign up to request clarification or add additional context in comments.

Comments

0

In your page you have

CommandName="deleteContact"

and in switch

case "deleteBtn"

they not match in your switch you must use the same CommandName

case "deleteContact"

1 Comment

I changed that, it's not the problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.