【问题标题】:Dropdownlist conditional postback?下拉列表条件回发?
【发布时间】:2013-06-11 10:00:58
【问题描述】:

我有一个下拉列表,其自动回发设置为 true,并且 selectedindexchanged 事件用于某些逻辑。但条件是当页面上的其他数据发生更改时,我需要通过显示确认对话框来警告用户更改。我正在使用 javascript 来执行此操作,但问题是即使函数返回 true,也不会发生回发。我不知道出了什么问题。有人可以帮忙吗?

function ValidateDataChange() {
        var isDataChanged = $('#<%=hdnDataIsChanged.ClientID %>').val();
        if (isDataChanged == "True") {
            alert(isDataChanged);
            return false;
        }

        return true;
    }

  <asp:DropDownList ID="ddlHierarchy" runat="server" AppendDataBoundItems="true" AutoPostBack="true"
                        onchange="return ValidateDataChange();" Enabled="false" OnSelectedIndexChanged="ddlHierarchy_SelectedIndexChanged">
                        <asp:ListItem Value="" Text="--Select Hierarchy--"></asp:ListItem>
                    </asp:DropDownList>
  <asp:HiddenField ID="hdnDataIsChanged" runat="server" />


 protected void ddlHierarchy_SelectedIndexChanged(object sender, EventArgs e)
    {
      //mycode
    }

【问题讨论】:

  • 为什么你在这里使用 Enabled="false"?是否触发了警报?
  • 在页面上执行搜索时将启用它。

标签: asp.net drop-down-menu


【解决方案1】:

selectedIndexChanged 绑定到 DDL 客户端的 onchange 事件。

通过写作

onchange="return ValidateDataChange();"

其实你在做:

onchange="return ValidateDataChange(); __doPostBack(this.id,'');"

因为返回,__doPostBack 永远不会被击中。

你应该试试:

onchange="if(!ValidateDataChange()) return false;" 

【讨论】:

    猜你喜欢
    • 2011-11-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多