事件验证:允许 __doPostBack 用于一个控件和*任何*参数
我正在使用
__doPostBack(clientIdOfSomeButton, someData);
JavaScript 创建 PostBack。问题是 someData
事先未知,并且事件验证启动,因为我无法 ClientScript.RegisterForEventValidation
每个 的可能值一些数据
。
到目前为止,我只能看到两种解决此问题的可能性:
- 关闭页面的事件验证,出于安全原因不建议这样做。
- 不要通过事件验证传递数据,而是通过 JavaScript 将数据放入某个隐藏文本字段中,然后调用 __doPostBack。那太丑了。
我是否错过了第三种选择?理想情况下,我想要类似 ClientScript.RegisterForEventValidationIgnoreArguments(myButton)
的东西,但这样的东西不存在......
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:
- Turn off event validation for the page, which is not recommended for security reasons.
- Instead of passing the data via event validation, put the data in some hidden text field via JavaScript 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...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果事先不知道 someData 那么服务器如何知道回发的含义?第二个参数是指示事件的类型或有关事件的特定信息,而不是用户输入的值。
我会注册一个自定义参数并以另一种方式传递 someData。
然后在客户端
Html
Javascript
上检索您的值
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.
And on the client
Html
Javascript
then retrieve your value