Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
javascript onchange事件到asp.net dropdownlist_Javascript_Jquery_Drop Down Menu_Onchange - Fatal编程技术网

javascript onchange事件到asp.net dropdownlist

javascript onchange事件到asp.net dropdownlist,javascript,jquery,drop-down-menu,onchange,Javascript,Jquery,Drop Down Menu,Onchange,是否可以使下拉列表选择触发发回到同一页面,并使用javascript将所选内容添加到url中作为querystring?问题是列表正在从某个sharepoint列表中动态加载。 如果我的网站是mysite.com/default.aspx 因此,当进行选择时,它应该重定向到mysite.com/default.aspx?key=selection 无法访问服务器,无法访问代码隐藏:( 未测试,也不确定正在重新加载页面的事件,例如(提交或锚定) 另一个选择(可能更好)来自 未测试,也不确定正在

是否可以使下拉列表选择触发发回到同一页面,并使用javascript将所选内容添加到url中作为querystring?问题是列表正在从某个sharepoint列表中动态加载。 如果我的网站是mysite.com/default.aspx 因此,当进行选择时,它应该重定向到mysite.com/default.aspx?key=selection

无法访问服务器,无法访问代码隐藏:(


未测试,也不确定正在重新加载页面的事件,例如(提交或锚定)

另一个选择(可能更好)来自

未测试,也不确定正在重新加载页面的事件,例如(提交或锚定)

另一个选择(可能更好)来自


我不确定您想做什么,但我想jquery是您问题的正确答案

无论如何,这可能会有帮助:

<script language="javascript" type="text/javascript">
    function xx(e) {
        alert("fired by " + "<%= DropDownList1.UniqueID %>" + "change ");
        __doPostBack("<%= DropDownList1.UniqueID %>", "");
    }
</script>


<asp:DropDownList ID="DropDownList1" runat="server" onchange="xx()">
    <asp:ListItem>q</asp:ListItem>
    <asp:ListItem>w</asp:ListItem>
    <asp:ListItem>e</asp:ListItem>
    <asp:ListItem></asp:ListItem>
</asp:DropDownList>

我不确定您想做什么,但我想jquery是您问题的正确答案

无论如何,这可能会有帮助:

<script language="javascript" type="text/javascript">
    function xx(e) {
        alert("fired by " + "<%= DropDownList1.UniqueID %>" + "change ");
        __doPostBack("<%= DropDownList1.UniqueID %>", "");
    }
</script>


<asp:DropDownList ID="DropDownList1" runat="server" onchange="xx()">
    <asp:ListItem>q</asp:ListItem>
    <asp:ListItem>w</asp:ListItem>
    <asp:ListItem>e</asp:ListItem>
    <asp:ListItem></asp:ListItem>
</asp:DropDownList>

我不完全确定你在问什么:你是否试图抑制现有的行为(这是一个自动回写)当下拉列表的值发生变化时?或者您正在尝试打开新窗口吗?我正在尝试回发,但URL附加为?key=whateverselected?我不完全确定您在问什么:您是否试图抑制现有行为(这是自动回发)当下拉列表的值更改时?或者您正在尝试打开新窗口?我正在尝试回发,但URL附加为?key=whateverselectedWhoops,完全假设您使用的是Jquery。抱歉,将其从单击事件切换为更改事件。您不应该有URL:…?而不是=…?哇,完全假设您使用的是Jquery。抱歉。将其从单击事件切换为更改事件。您不应该有url:…?而不是=?
$(document).ready(function() {

   var selectedOption = $("#DropDownList1 option:selected").text();

  $("#DropDownList1").change(function() {
    $.ajax({
      type: "POST",
      url: "mysite.com/default.aspx?key=" + selectedOption,
      data: "{}",
      contentType: "application/json; charset=utf-8",
      dataType: "json",
      success: function(msg) {
        // Replace the div's content with the page method's return.
        alert("this worked!");
      }
    });
  });
});
<script language="javascript" type="text/javascript">
    function xx(e) {
        alert("fired by " + "<%= DropDownList1.UniqueID %>" + "change ");
        __doPostBack("<%= DropDownList1.UniqueID %>", "");
    }
</script>


<asp:DropDownList ID="DropDownList1" runat="server" onchange="xx()">
    <asp:ListItem>q</asp:ListItem>
    <asp:ListItem>w</asp:ListItem>
    <asp:ListItem>e</asp:ListItem>
    <asp:ListItem></asp:ListItem>
</asp:DropDownList>
Protected Sub DropDownList1_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
    MsgBox("Do whatever you want here")
End Sub