出现错误的揭示如下:
Invalid postback or callback argument. Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %> in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.
在网上看了一下,没有一个完整的解决方法。
这个问题搞了我一天的时间,终于搞定了。一个字“爽”。
解决方法:
在.aspx页面中的<%@ Page …… %>语句中加上属性EnableEventValidation="false"
然后在页面里面有一个DropDownList控件是动态填充的,点击按钮后取不到的值
解决方法:
在protected void Page_Load(object sender, EventArgs e){}前面写上如下:
protected override void Render(HtmlTextWriter writer)
{
ClientScript.RegisterForEventValidation(this.ddlType.UniqueID, "argument");//ddlType为DropDownList控件的名称
base.Render(writer);
}
然后在Button的事件里面取DropDownList的SelectedValue值的方法为:Request.Form[this.ddlType.UniqueID.ToString()]
注意:从Request.Form[this.ddlType.UniqueID.ToString()]得到解决的值如果是中文,有乱码。所以最好是传值
同理,把服务器控件转换为客户端可以识别的控件ID为:ddlType.UniqueID