简体   繁体   English

等待用户输入

[英]Wait for user input

i have a process that makes calls to a webservice and handles the responses, some of the responses require some user input so they can be handled.我有一个调用 web 服务并处理响应的进程,一些响应需要一些用户输入,以便可以处理它们。 When user input is required i want to trigger an event, in the event handler i want to display a form to the page then wait until the user input is posted back then have the event handler return the user input to the calling method.当需要用户输入时,我想触发一个事件,在事件处理程序中我想向页面显示一个表单,然后等到用户输入被发回,然后让事件处理程序将用户输入返回给调用方法。

I am having difficulty with the making the event handler wait for the post back before returning the input, i don't even know if its possible.我很难让事件处理程序在返回输入之前等待回帖,我什至不知道它是否可能。

Personally, I prefer Noldorin's suggestion of figuring out a workflow and using that to determine when to ask for input.就个人而言,我更喜欢 Noldorin 的建议,即找出工作流程并使用它来确定何时请求输入。 Keep in mind that server events won't do anything as far as client-side rendering is concerned unless they happen when the user is making their request...in which case you've already got a workflow and have no need for events.请记住,就客户端渲染而言,服务器事件不会做任何事情,除非它们发生在用户发出请求时......在这种情况下,您已经有了工作流程并且不需要事件。

You could work around this by keeping the client machine in communication with the server.您可以通过使客户端计算机与服务器保持通信来解决此问题。 For example check for new events in the Tick event of an <asp:Timer> control.例如,检查<asp:Timer>控件的 Tick 事件中的新事件。 This solution is practical if your goal is to, for example, have an update panel or something that says the server is XX% done processing the user's request, and ask for user input once processing is done.如果您的目标是,例如,有一个更新面板或表明服务器已完成 XX% 的用户请求处理,并在处理完成后要求用户输入,则此解决方案是实用的。

If I understand correctly, I think the problem here is that you're trying to solve the problem using a very simple event-based system.如果我理解正确,我认为这里的问题是您正在尝试使用非常简单的基于事件的系统来解决问题。 What you need to be doing is creating your own (very simple) workflow system for such a task and also try to separate out some of the back-end logic from the UI handling (ASP.NET MVC framework would be ideal for this, though I see you are using WebForms, which nonetheless isn't a big problem).您需要做的是为此类任务创建自己的(非常简单的)工作流系统,并尝试将一些后端逻辑从 UI 处理中分离出来(不过,ASP.NET MVC 框架将是理想的选择)我看到您正在使用 WebForms,但这并不是什么大问题)。 Now this "workflow" doesn't necessarily need to be complex.现在这个“工作流程”并不一定需要很复杂。 Start off by breaking down the actions performed by your application into some sort of flow diagram.首先将应用程序执行的操作分解为某种流程图。 If you can see pretty straightforward dependencies, then it may just be a matter of implementing a basic state machine.如果您可以看到非常简单的依赖关系,那么它可能只是实现一个基本的 state 机器的问题。 As a general pointer to dealing with states in web applications (of all kinds: application, session, view), have a read through some of the links on this page .作为在 web 应用程序(各种:应用程序,session,查看)中处理状态的一般指针,请阅读此页面上的一些链接。 I'm afraid I can't really provide you with anything more specific from what you've described (perhaps I'm missing something obvious however).恐怕我无法真正为您提供您所描述的更具体的内容(但也许我遗漏了一些明显的东西)。 If you'd like to clarify the tasks that your website/web app needs to perform, then I might be able to give some code examples, but I suspect that just treating this problem analytically/from a flow perspective should give you a good solution.如果您想澄清您的网站/网络应用程序需要执行的任务,那么我可能会提供一些代码示例,但我怀疑仅从分析的角度/从流程的角度处理这个问题应该会给您一个很好的解决方案.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM