ASP.NET/VB.NET: Dropdownlist SelectedIndexChanged not firing with onchange=“javascript:return true;”

半腔热情 提交于 2019-12-05 13:48:30

You shouldn't need that at all. Just set AutoPostBack to true, and if you need to escape validation set CausesValidation to false.

<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true" CausesValidation="false" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" />

For some reason, I thought you could cancel a dropdown's server event by returning false on the client side's onchange event like you could with a button's onclick event (eg, onclick="javascript:return false;").

What I ended up doing is checking a condition in a function. If true, it fires this:

__doPostBack("<%=dd2.ClientID %>", '');

Otherwise, it doesn't.

Kelly
<asp:DropDownList ID="page_size" runat="server" **AutoPostBack="true"** OnSelectedIndexChanged="page_size_SelectedIndexChanged">
                            </asp:DropDownList>

Add Autopostback="true did the trick for me.

Shyam Sharma
__doPostBack("<%=dd2.ClientID %>", '');

This worked for me.

This was my drop down:

<asp:DropDownList ID="ddlbranchname" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlBranchChanged" 
onchange="return CheckDate();" CausesValidation="false" CssClass="dropdown">
</asp:DropDownList>

Here is my jquery function:

function CheckDate() {
    var date = document.getElementById('<%= ucDateTimeStart.FindControl("txtDateTime").ClientID %>').value;
    if (date == '') {
        alert("Please select a valid date.");
        return false;
    }
    else {
        __doPostBack("<%=ddlbranchname.ClientID %>", '');
        return true;
    }
    return true;
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!