开发者

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

I'm using

__doPostBack(clientIdOfSomeButton, someData);

to create a PostBack in JavaScript. The problem is that someData is not known in advance, and event validation kicks in because I cannot ClientScript.RegisterForEventValidation every possible value of someData.

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

  1. Turn off event validation for the page, which is not recommended for security reasons.
  2. Instead of passing the data via event validation, put the data in some hidden text field via JavaScript 开发者_Go百科and then call __doPostBack. That's ugly.

Is there some third option that I've missed? Ideally, I'd like something like ClientScript.RegisterForEventValidationIgnoreArguments(myButton), but something like this does not exist...


If someData is not known in advance then how does the server know the meaning of the postback? The second argument is to indicate the type of event or specific information concerning the event, not a user inputted value.

I would register for a custom argument and pass the someData another 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 retrieve your value

if(Request["__EVENTARGUMENT"] == "customArgument")
{
   var customArgument = Request["customArgument"]
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜