【问题标题】:use onclientclick attribute and code behind asp net在 asp net 后面使用 onclientclick 属性和代码
【发布时间】:2017-02-09 12:55:55
【问题描述】:

我的中继器中有这个链接按钮,它应该编辑用户。我刚刚调试过,我看到除非我提交,否则代码永远不会转到后面的代码(aspx.cs),但在选择时不会。我该如何解决这个问题?

ASPX:

 <asp:Repeater runat="server" OnItemCommand="rptList_OnItemCommand" ID="rptList">
       <ItemTemplate>
                <%# OperatorId.HasValue && OperatorId == Convert.ToInt32(Eval("ID"))? "<tr style='background-color: #94C5E1;'>" : "<tr>" %>
                      <td>
                        <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>
                        <div id="modalEdit" class="modal">
                            <div class="modal-content">
                                <p style="margin-left: 50px;">
                                    <img src="Images/Icons/Sip.png" alt="" />
                                    <%# Eval("FirstName") %> <%# Eval("SurName") %>
                                </p>
                                <br />
                                <asp:DropDownList CssClass="ddlNodeClass" runat="server" ID="ddlNodeEdit" />
                                <asp:DropDownList CssClass="ddlTranslatorClass" runat="server" ID="ddlTranslatorEdit" />
                                <asp:LinkButton ToolTip="TRNSLTCancel" CommandArgument='<%# Eval("ID") %>' ID="btnNo" runat="server" CssClass="btnCancelClass" OnClientClick="return Cancel(this)">
                                    <asp:Image ImageUrl="Images/Icons/Cancel-22x22.png" ID="SaveContact" runat="server" ClientIDMode="Static" />
                                </asp:LinkButton>
                                <asp:LinkButton ToolTip="TRNSLTSave" CommandName="submitBtn" CommandArgument='<%# Eval("ID") %>' ID="btnYes" runat="server" CssClass="btnSaveClass">
                                    <asp:Image ImageUrl="Images/Icons/Check-22x22.png" ID="SaveOperator" runat="server" ClientIDMode="Static" />
                                </asp:LinkButton>
                            </div>
                        </div>
                    </td>
       </ItemTemplate>

C#:

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

        var ddlNodeEdit = (DropDownList)e.Item.FindControl("ddlNodeEdit");
        var ddlTranslatorEdit = (DropDownList)e.Item.FindControl("ddlTranslatorEdit");

    switch (e.CommandName)
    {
        case "deleteBtn":
            OperatorId = operatorId;
            break;

        case "noBtn":
            break;

        case "yesBtn":
            _administrationSystem.DeleteOperator(tellusUserId, operatorId);
            Response.Redirect("Attendants.aspx");
            break;

        case "selectBtn": //The code never enters here
            var profile = _administrationSystem.GetOperatorForEdit(tellusUserId, operatorId);

            if (profile != null)
            {
                ViewState["Profile"] = profile;
            }
            break;

        case "submitBtn": //The code enters here though
            _administrationSystem.UpdateOperator(tellusUserId, operatorId, TellusUser.UserID, ddlNodeEdit.SelectedIndex + 1, Convert.ToInt64(ddlTranslatorEdit.SelectedValue), "");
            ViewState["ID"] = operatorId;
            break;
    }
}

JS:

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

【问题讨论】:

  • 你能告诉我你的page_load事件代码吗。
  • 页面加载时没有发生任何相关的事情。
  • 哪个链接按钮? "[...] but not when selection" 是什么意思?
  • @Malphai 我认为您在OnClientClick ="return PopupEdit(this)" 上尝试做的事情很重要。 OnClientClick 应该调用客户端脚本。所以需要在PopupEdit(...) 函数中显示一些关于你在做什么的代码。
  • 查看更新的答案。

标签: c# asp.net .net switch-statement repeater


【解决方案1】:

如果我是正确的OnClientClick="return PopupEdit(this)"

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

返回一个假
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 false;
}

return false 停止回发。

希望对你有帮助

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-06-14
    • 2013-11-30
    • 2018-01-28
    • 1970-01-01
    • 1970-01-01
    • 2018-05-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多