Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/452.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.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 如何在客户端填充drop box数据的位置获取drop box selected值_Javascript_Asp.net - Fatal编程技术网

Javascript 如何在客户端填充drop box数据的位置获取drop box selected值

Javascript 如何在客户端填充drop box数据的位置获取drop box selected值,javascript,asp.net,Javascript,Asp.net,我有一个页面有两个下拉框。第二个下拉框中的数据将根据第一个下拉框中选定的数据而更改。第一个下拉框中更改的数据位于客户端脚本中。现在,我尝试在服务器端的第二个下拉框中获取选定值,但没有。如何解决此问题 以下是代码: <div class="field"> <input type="hidden" id="ddlFormatOriginalData" name="ddlFormatOriginalData" runat="server" /> <asp:

我有一个页面有两个下拉框。第二个下拉框中的数据将根据第一个下拉框中选定的数据而更改。第一个下拉框中更改的数据位于客户端脚本中。现在,我尝试在服务器端的第二个下拉框中获取选定值,但没有。如何解决此问题

以下是代码:

<div class="field">
    <input type="hidden" id="ddlFormatOriginalData" name="ddlFormatOriginalData" runat="server" />
    <asp:DropDownList ID="d1" runat="server">
    </asp:DropDownList>
</div>

<div class="field">
    <input type="hidden" id="ddlFormatOriginalData" name="ddlFormatOriginalData" runat="server" />
    <asp:DropDownList ID="d2" runat="server">
    </asp:DropDownList>
</div>

但是我没有从val那里得到任何东西,尽管在firebug中,d2下拉框显示了不同的列表

protected override void OnInit(EventArgs e)
{
     var postedOptionValue = Request.Form[d2.UniqueID];
     d2.Items.Add(new ListItem(postedOptionValue));
     base.OnInit(e);
}
但是你应该注意以下例外情况

Invalid postback or callback argument.  
使用启用事件验证

   <pages enableEventValidation="true"/> 

在配置上或

    <%@ Page EnableEventValidation="true" %> 

在一页中。出于安全目的,此功能验证回发或回调事件的参数是否源自最初呈现它们的服务器控件。
如果数据有效且符合要求,请使用ClientScriptManager。
RegisterForEventValidation方法,以便注册回发或回调数据以进行验证

编辑1 更多阅读-

尝试使用JQuery数据-例如:

<div id="test" data-cool="demo"></div>
您还可以使用它设置更新变量:

$("#test").data("cool", "really cool!"); // updates the data-cool field to: 'really cool!'

@RJUy为什么要使用隐藏字段。你好,Krshekhar,谢谢你提供的信息。我现在就试着实施,如果一切顺利,我会告诉你的。。隐藏字段还有其他用途…:)当我添加此选项时,EnableEventValidation=“true”在提交按钮时出错,这是基于我对EnableEventValidation=“true”将导致安全问题的研究。我认为公司不会接受这种解决方案。我尝试了另一种解决方案,改为在服务器端设置值。我希望这个能起作用。不过非常感谢你的帮助。我真的很感谢您的时间。您可以利用html
列表选项
并在隐藏字段中设置所选值。这种方法不需要
EnableEventValidation=“true”
<div id="test" data-cool="demo"></div>
$("#test").data("cool"); // outputs: 'demo'
$("#test").data("cool", "really cool!"); // updates the data-cool field to: 'really cool!'