简体   繁体   中英

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:

Invalid postback or callback argument. Event validation is enabled using 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.

But when I add the Page directive EnableEventValidation = "false" on my page, no error but does not fire my event.

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.

So, in Page_Load:

if(!IsPostBack)
  // Bind Repeater Data here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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