简体   繁体   English

两个ASP.NET页面之间的预加载页面

[英]Preloading page between two asp.net pages

I posed a question that related where I could display "Page loading" in asp.net page using jQuery. 我提出了一个问题,该问题与使用jQuery在asp.net页面中显示“页面加载”的位置有关。 But, I had no luck. 但是,我没有运气。

So, say I have page1 and it navigates to page2 and page2 doesn't some heavy data access. 因此,假设我有page1,它导航到page2,而page2并没有进行大量的数据访问。 Is there any way I could show the "preloading" page while the page2 is finished. page2完成后,有什么方法可以显示“预加载”页面。

I want to navigate from Page1 -> "Preload" -> Page2(once page2 is completed). 我想从Page1->“ Preload”-> Page2导航(一旦page2完成)。

I want to know if this is possible using Javascript in the code behind. 我想知道在后面的代码中使用Javascript是否可行。

Thanks. 谢谢。

The way you would typically do this is have a page that shows the message and uses AJAX, in my example using jQuery, to load the other page onto the current page. 通常,这样做的方式是有一个页面显示消息并使用AJAX(在我的示例中使用jQuery)将另一页加载到当前页面上。

<body>
   <div id="content">
   Page loading
   </div>

   <script type="text/javascript">
        $(function() {
            $('#content').load('/url/to/other/page');
        });
   </script>
</body>

I've omitted loading jQuery itself. 我省略了加载jQuery本身。

Note: you could do this on a single page by having it generate different content based on some query parameter. 注意:您可以在单个页面上执行此操作,方法是根据某些查询参数生成不同的内容。 You don't need to actually have a separate "loading" page -- though you could probably make that work for several different pages as well. 您实际上不需要有一个单独的“加载”页面-尽管您可能也可以在多个不同的页面上使用它。

If using JavaScript is OK, redirect the user to the Preload page, and then use JavaScript to take the user to Page2. 如果可以使用JavaScript,则将用户重定向到“预加载”页面,然后使用JavaScript将用户带到Page2。 This will make the Preload page stay visible while Page2 is loading. 这将使Preload页面在Page2加载时保持可见。

(Also, "JavaScript in the codebehind"? Don't tell me you're using JScript.NET or something as your server side language) (此外,“隐藏在代码后面的JavaScript”?不要告诉我您使用的是JScript.NET还是某些服务器端语言)

No matter what you do, to begin loading Page2 you'll have to navigate away from Page1 (unless you get complicated and wrap your pages in another container on a single page and navigate within your container). 无论您做什么,要开始加载Page2,您都必须离开Page1(除非您变得很复杂,并且将页面包装在另一个页面中的单个页面中并在您的容器中导航)。

Otherwise the default content for Page2 should be a "Preloading" message that gets taken away once the document has finished loading its content. 否则,Page2的默认内容应该是“预加载”消息,一旦文档完成其内容加载,该消息就会被删除。

Is a possible solution to have an almost empty page with a few placeholder divs in the right places containing a loading image. 一个可能的解决方案是在正确的位置放置一个几乎空白的页面,并在其中包含一些占位符divs,其中包含加载图像。 Then run web service calls to populate each placeholder in jquery/javascript? 然后运行Web服务调用以在jquery / javascript中填充每个占位符?

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

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