Malphai
Malphai

Reputation: 317

Combining asp net linkbutton onclick and onclientclick with javascript popup

I have this popup that I want to stick when editing an operator. The problem is that I return trueso that I can get access to code-behind, but when doing this, my popup instantly closes, if I return false: the popup will stick but the code will never go to code-behind. What should I do? (Also, my linkbutton is inside a repeater)

JavaScript:

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

    return true; //Right here is the problem.
}

ASPX:

<asp:LinkButton CommandName="selectBtn" ToolTip="TRNSLTEdit" ID="btnEdit" CssClass="editOperator" runat="server" CommandArgument='<%# Eval("ID")%>' OnClientClick="return PopupEdit(this)">
<asp:Image ImageUrl="Images/Icons/Edit-16x16.png" ID="EditVisitor" runat="server" />
</asp:LinkButton>

C#:

    protected void rptList_OnItemCommand(object source, RepeaterCommandEventArgs e)
    {
         var tellusUserId = TellusUser.UserID;
         var operatorId = Convert.ToInt64(e.CommandArgument);

               switch (e.CommandName)
               {
                case "selectBtn":
                var btnEdit = (LinkButton)e.Item.FindControl("btnEdit");
                btnEdit.Attributes.Add("onclick", "return false;"); //I tried this, but does not work.
                var operatorsDataSet = _administrationSystem.GetOperatorForEdit(tellusUserId, operatorId);

                if (operatorsDataSet != null)
                {
                    ViewState["OperatorsForEdit"] = operatorsDataSet;
                }
                break;
                }
      }

Upvotes: 0

Views: 1159

Answers (1)

Kevin Shah
Kevin Shah

Reputation: 1617

Your popup is getting close because of page is going to server so popup dialog is closed. you have to open your popup from code behing from your linkbutton's click event in your C# code you have to register your script like

ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "PopupEdit", "PopupEdit("+lnkControl.ClientID+");", true);

This will work

Upvotes: 1

Related Questions