简体   繁体   English

带有中继器的火灾事件进入中继器

[英]Fire Event With Repeater into Repeater

Good Afternoon People, I'm using a Repeater, and within that repeater there is another repeater, there is a button for each item. 下午好,我在使用中继器,在该中继器中有另一个中继器,每个项目都有一个按钮。 When I click on one of these buttons asp.net returns me the following error: 当我单击这些按钮之一时,asp.net向我返回以下错误:

Invalid postback or callback argument. 无效的回发或回调参数。 Event validation is enabled using in configuration or <%@ Page EnableEventValidation="true" %> in a page. 使用配置或页面中的<%@页面EnableEventValidation =“ true”%>启用事件验证。 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. 如果数据有效且预期,请使用ClientScriptManager.RegisterForEventValidation方法以注册回发或回调数据以进行验证。

But when I add the Page directive EnableEventValidation = "false" on my page, no error but does not fire my event. 但是,当我在页面上添加Page指令EnableEventValidation =“ false”时,没有错误,但不会触发事件。

How can this be resolved? 如何解决?

Do you bind the data at each postback? 您是否在每次回发时都绑定数据? The problem probably originates from the fact, that the Repeater that sent the event is not there anymore after the postback, and a new Repeater is created every Postback. 问题可能源于以下事实:发送事件的转发器在回发之后不再存在,并且每次回发都会创建一个新的转发器。 That's why the event validation fails, you cannot fire events from one dynamically created control to another one. 这就是事件验证失败的原因,您无法将事件从一个动态创建的控件触发到另一个控件。 It has to be the same control. 它必须是相同的控件。

The easy solution would be to only bind the data on the first load of the Page and keep ViewState enabled. 一种简单的解决方案是仅在页面的第一次加载时绑定数据,并保持ViewState为启用状态。

So, in Page_Load: 因此,在Page_Load中:

if(!IsPostBack)
  // Bind Repeater Data here

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM