关于asp.net 2.0 的一个问题 "ClientScript.RegisterForEventValidation"求助
我用javascript从数据库导出xml格式的信息,然后将之加载到服务器端的Dropdown控件上以实现两个或三个联动下拉菜单的联动,但在提交时发现如下问题:
1.提交之前明明选定了下拉菜单的内容(其内容是通过javascript加载的),但在提交时却发现该下拉菜单内容被莫名其妙的恢复到了服务器端控件的初始内容(如在javascript加载之前为空的状态)。
2.提交之后,出现一报错信息如下:
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.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentException: 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.
我搜索了一下国外的网站,好像有两种解决方案,第一种是:将当前页的EnableEventValidation属性设为false;
EnableEventValidation="false"
第二种是:在code中重载render()方法
protected override void Render(HtmlTextWriter writer)
{
Page.ClientScript.RegisterForEventValidation(this.lst_SubArticleCategoryKey.UniqueID);
Page.ClientScript.RegisterForEventValidation(this.lst_ParentArticleCategoryKey.UniqueID);
base.Render(writer);
}
或
protected override void Render(HtmlTextWriter writer)
{
ClientScript.RegisterForEventValidation(this.lst_SubArticleCategoryKey.UniqueID, "One");
base.Render(writer);
}
不过好像都解决不了问题;用第一种方法不报错了,但下拉菜单内容在提交时还是会被清空;而用第二种方法因为我是动态加载的,我不知道该怎么用;
那位高人指点一下,困扰了好几天了;感激不尽。
相关链接:
http://www.alexthissen.nl/weblog/PermaLink.aspx?Guid=cadcb2b4-d3c3-406b-a9a6-ae6c2bbfc758
http://blog.csdn.net/web718/archive/2005/09/06/472917.aspx