对 Silverlight 4 中的异步验证感到困惑
假设我的表单上有一个用户名字段,我想通过进行服务器端 [Invoke]
调用来使用异步验证来验证它。考虑一下我在表单中还有 2-3 个字段,然后我有一个提交方法,如果一切顺利的话,它基本上会将用户添加到数据库中。现在,由于验证是异步的,用户仍然可以输入其他字段,如果对服务器的调用未完成并且在返回响应之前客户端完成填写表单并点击提交按钮怎么办?我一定会得到一个错误。
我该如何处理这些类型的错误?我应该禁用“提交”按钮吗?如果是,那么如何?因为我在 RIA 扩展方法中连接异步调用逻辑,即在客户端的部分类中,例如:
public void OnUsernameChanging()
{
//make service call and handle it..
}
此方法位于实体类中,而不是在代码后面。因此,我无法获取页面上提交按钮的引用并禁用它。我该如何处理?一种选择是,当我使用 MVVM 模式时,我总是使用 Messenger 类来救援,通过它我可以禁用它。如果 Messenger 类不可用,还有其他选择吗?
Say I have a username field on my form and I want to validate it using async validation by making a server side [Invoke]
call. Consider I have 2-3 more field in the forms and then I have a submit method which will basically add the user in the database if all goes well. Now because the validation is async, user can still input other fields and what if the call to the server was not completed and before the response is returned the client completes filling the form and hits the submit button? I am bound to get an error.
How do I handle these types of error? Should I disable Submit button? If yes, then how? because I am hooking up the Async call logic in the RIA extension methods i.e in partial class on the client like:
public void OnUsernameChanging()
{
//make service call and handle it..
}
This method is in Entity class and not in code behind. Thus I cannot get a reference to submit button on Page and disable it. How do I handle it? One option is as I am using MVVM pattern, I always have Messenger class to the rescue and through it I can disable it. Are there any other options if the Messenger class was not available?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当我实施类似的解决方案时,我选择了旧设备;
IE 异步客户端验证用于显示目的,真正的验证应该在实体元类中,或者如果更具体,则在相关的
[update]
和[insert]
方法中服务。下面是一个简单的例子:不要阻止用户进行提交,而是在提交时放置一个忙碌指示器或其他东西。
When I implemented a similar solution I went by the old device;
IE async client side validation is used for display purposes, the real validation should either be in entity metaclasses or if more specific in the relevant
[update]
and[insert]
methods of the service. Simple example below:Do not prevent the user from doing a submiy, but put up a busyindicator or something else when submitting.