页面.EnableEventValidation = false不识别新的下拉列表值
Page.EnableEventValidation = false does not recognize new dropdownlist values
我的测试表单有1个dropdownlist
和2个buttons
。
<form id="form1" runat="server">
<asp:DropDownList ID="DropDownListTest" runat="server" >
<asp:ListItem>Value 0</asp:ListItem>
<asp:ListItem>Value 1</asp:ListItem>
<asp:ListItem>Value 2</asp:ListItem>
</asp:DropDownList>
<asp:Button ID="ButtonClient" runat="server" Text="Button" OnClientClick="ChangeDropDown(); return false;" />
<asp:Button ID="ButtonServer" runat="server" Text="Server" onclick="ButtonServer_Click" />
</form>
这是javascript
函数ChangeDropDown()
:
function ChangeDropDown() {
for (i = document.getElementById("<%=DropDownListTest.ClientID%>").options.length - 1; i >= 0; i--) {
document.getElementById("<%=DropDownListTest.ClientID%>").remove(i);
}
var opt = document.createElement("option");
opt.text = "Complete";
opt.value = "Complete";
document.getElementById("<%=DropDownListTest.ClientID%>").options.add(opt);
var opt2 = document.createElement("option");
opt2.text = "Not Complete";
opt2.value = "Not Complete";
document.getElementById("<%=DropDownListTest.ClientID%>").options.add(opt2);
}
后面的代码是:
protected void ButtonServer_Click(object sender, EventArgs e)
{
string val = this.DropDownListTest.SelectedValue;
}
protected void Page_PreInit(object sender, EventArgs e)
{
Page.EnableEventValidation = false;
//"Invalid postback or callback argument" if I remove this.
}
假设我点击button ButtonClient
(这会改变下拉框的值),选择"完成",然后点击ButtonServer
。在codebehind中,this.DropDownListTest.SelectedValue
的值等于" value 0"而不是"Complete"。
我明白为什么我得到的问题,但有没有另一个解决方案除了添加项目代码背后?
您无法以标准方式获得该值,因为服务器不知道下拉列表的项已被更改。
但是,您可以直接从请求中获取值:
protected void ButtonServer_Click(object sender, EventArgs e)
{
string val = Request[this.DropDownListTest.UniqueID];
}
相关文章:
- 如何使用jQuery选择下拉列表的值
- 将jsp文件下拉列表中的选定项分配给一个java变量(比如String selection)
- Javascript按钮下拉列表
- jQuery表单添加不适用于下拉列表
- 用每小时的差值填充数组/列表-从下拉列表中给定两个时间值
- 禁用jQuery中的下拉列表
- 如何在按钮中显示下拉列表中选定的元素
- 如何在从多选下拉列表中选择选项值时动态生成文本框
- 如何使用PHP和JS级联三个下拉列表
- 如何在使用剑道 MVVM 下拉列表时强制选择第一项
- 语义ui如何使用javascript启用或禁用下拉列表
- 无法使用PHP动态设置下拉列表中的值
- 如何根据对具有多行的先前列表的选择来动态加载下拉列表
- 下拉列表在使用z索引放置在前面后停止工作
- 从多维嵌套json数组创建下拉列表
- 如何在剑道下拉列表中按文本和值搜索
- 使用下拉列表筛选列表(ul>li)
- 如何使用jquery从下拉列表(javascript)中选择192.168.3.0进行测试自动化
- 使用codeigniter的多链下拉列表
- 页面.EnableEventValidation = false不识别新的下拉列表值