简体   繁体   English

我的ASP.NET页如何在客户端代码和服务器代码之间来回切换几次?

[英]How can my ASP.NET page go back and forth from client to server code and back several times?

OK, the tite seems a little confusing, so I'll try to explain more thoroughly... 好吧,这个小礼貌似乎有点令人困惑,所以我将尝试更彻底地解释...

The process the page does currently follows the following sequence: - User clicks a button - server-side code goes retrieve data from the DB and exposes said data to the client using, populating, let's say, hidden fields. 该页面当前执行的处理过程按以下顺序进行:-用户单击按钮-服务器端代码从数据库中检索数据,并使用填充字段(例如隐藏字段)将这些数据公开给客户端。 - client-side code uses this data to fire up a an ActiveX component which performs a few tasks with the data provided. -客户端代码使用此数据来启动ActiveX组件,该组件将使用提供的数据执行一些任务。

And this works fine, however, we need to optimize the process because the ActiveX component is not fit to handle high volumes of data. 这样做很好,但是,由于ActiveX组件不适合处理大量数据,因此我们需要优化流程。 We need to send data into "blocks" to the component, rather them send all data at once as it is done today. 我们需要将数据发送到组件的“块”中,而不是像今天那样一次发送所有数据。

However, I just hit a roadblock here, on how can I make the page go back and forth from server to client code multiple times? 但是,我在这里遇到了一个障碍,即如何使页面多次在服务器代码和客户端代码之间来回移动? Like... "user clicks a button, server retrieves first block of data, sends to client, client executes ActiveX for the first block, client requests next block, server retrieves second block, sends to client, client executes ActiveX for the second block, client requests third block... and so on"? 如...“用户单击一个按钮,服务器检索第一个数据块,发送给客户端,客户端对第一个块执行ActiveX,客户端请求下一个块,服务器检索第二个块,向客户端发送,客户端对第二个块执行ActiveX ,客户要求第三个阻止...依此类推”? I can't get past the first request, since I can't register a client script block 2 times and expect AJAX to handle those multiple sequential callbacks... 我无法超越第一个请求,因为我无法注册客户端脚本块两次,并且期望AJAX处理这些多个顺序回调...

Or is there a way? 还是有办法?

This sounds more like an architectural issue than anything else. 这听起来更像是一个体系结构问题。

What you should be doing here is: 您在这里应该做的是:

1) User clicks a button. 1)用户单击一个按钮。 This is NOT a regular submit button. 这不是常规的提交按钮。 Just a plain old button that executes some local javascript. 只是一个执行某些本地javascript的普通按钮。

2) Local javascript makes an AJAX request to determine how many records are available. 2)本地javascript发出AJAX请求,以确定有多少条记录可用。

3) That javascript then does a loop based on the number of available records divided by the amount you want to pull per chunk. 3)然后,该javascript将根据可用记录数除以您要提取的每个块的数量进行循环。

3.a) Execute AJAX request for a chunk 3.a)对块执行AJAX请求

3.b) Throw the data into your ActiveX control - which, btw, I really would suggest you guys think about getting rid of. 3.b)将数据放入ActiveX控件中-顺便说一句,我真的建议你们考虑摆脱它们。 There are so many issues with ActiveX that it's not even funny. ActiveX有很多问题,甚至都不是很有趣。

4) Repeat 3.a and 3.b until completion. 4)重复3.a和3.b,直到完成。

You'll notice that at no point was a full post back performed. 您会注意到,根本没有执行完整的回发。 You'll also notice that you shouldn't have to register any client script blocks. 您还将注意到,您不必注册任何客户端脚本块。

Now the draw back here is purely in the ActiveX control. 现在,这里的缺点完全在ActiveX控件中。 Can it be instantiated from javascript multiple times in a page or are you forced to only use a single instance? 可以在页面中多次从javascript实例化它,还是只能使用一个实例?

If it's limited to a single instance, then you'll need a different approach entirely. 如果仅限于单个实例,那么您将完全需要另一种方法。

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

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