I'm trying to register some buttons for event registration because I keep getting the "Invalid postback or callback argument". Since I'm passing the buttons' events manually through __doPostBacks(), due to client-side validation, I think it has something to do with that.
I overrode Render to use RegisterForEventValidation like this:
protected override void Render(HtmlTextWriter writer)
{
ClientScript.RegisterForEventValidation(btnNuevo.UniqueID);
ClientScript.RegisterForEventValidation(btnBorrar.UniqueID);
ClientScript.RegisterForEventValidation(btnEditar.UniqueID);
ClientScript.RegisterForEventValidation(btnAlquilar.UniqueID);
base.Render(writer);
}
But the __doPostBacks on the client-side .aspx page are written like this:
...
__doPostBack('<%= btnNuevo.UniqueID %>', "");
...
__doPostBack('<%= btnBorrar.UniqueID %>', selected.childNodes[0].innerText);
...
__doPostBack('<%= btnEditar.UniqueID %>', index);
...
__doPostBack('<%= btnAlquilar.UniqueID %>', indexaux);
where selected.childNodes[0].innerText, index and indexaux are strings. This still throws that Exception.
I know there's an overload of RegisterForEventValidation where you pass it a key for the control, and the arguments.
The thing is, I don't know how to write that. I'm not suppossed to know fore-hand what the argument is going to be, since selecter, index and indexaux depend on the user interaction with the page (namely, selecting a row in a GridView). The only examples I find are those where the argument is always the same, so they just write RegisterForEventValidation("nameOfControl", "XXXX"), where "XXXX" is a fixed string.
Any ideas regarding how to write this, or if this isn't the problem?
Thanks.
我不知道您是否设置了这种方法,但是可以在page指令中将EnableEventValidation
设置为false:
<%@ Page Language="C#" EnableEventValidation="false" ... %>
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.