Event validation: allow __doPostBack for one control and * any arguments *

I use

__doPostBack(clientIdOfSomeButton, someData); 

to create a postback in javascript. The problem is that someData not known in advance, and event checking is triggered because I cannot ClientScript.RegisterForEventValidation all possible values ​​of someData .

So far, I see only two possibilities to solve this problem:

  • Disable event checking for a page that is not recommended for security reasons.
  • Instead of passing data through event checking, put the data in some hidden text box via JavaScript, and then call __doPostBack . This is ugly.

Is there any third option that I missed? Ideally, I would like something like ClientScript.RegisterForEventValidationIgnoreArguments(myButton) , but something like this does not exist ...

+4
source share
1 answer

If some data is not known in advance, then how does the server know the value of the postback? The second argument is to indicate the type of event or specific information about the event, rather than the value entered by the user.

I would register for a user argument and pass someData in a different way.

 ClientScript.RegisterForEventValidation(clientIdOfSomeButton, "CustomEvent"); 

And on the client

HTML

 <input name="customArgument" type="hidden" value="" /> 

Javascript

 document.forms[0].customArgument = someData; __doPostBack(clientIdOfSomeButton, ''); 

then extract your meaning

 if(Request["__EVENTARGUMENT"] == "customArgument") { var customArgument = Request["customArgument"] } 
+6
source

All Articles