关于asp.net 2.0 的一个问题 "ClientScript.RegisterForEventValidation"求助

zeshengnk 2006-01-11 10:16:34
我用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


...全文
109 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
saucer 2006-01-12
  • 打赏
  • 举报
回复
>>>其内容是通过javascript加载的

参考我在这个帖子里的回复
http://community.csdn.net/Expert/topic/4502/4502111.xml?temp=.4838526
zeshengnk 2006-01-11
  • 打赏
  • 举报
回复
加到50分
zeshengnk 2006-01-11
  • 打赏
  • 举报
回复
刚注册的用户,不知道怎样发分,请大家见谅

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧