ASP.NET 服务器不异步处理页面 [英] ASP.NET Server does not process pages asynchronously

查看:32
本文介绍了ASP.NET 服务器不异步处理页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有按钮的页面,我想通过单击按钮异步加载 2 个数据网格.

I have a page with button, and i want to load 2 data grids with data asynchronously by cliking the button.

这是页面的代码,我使用 jquery 来调用其他 2 个页面,这将产生我的 html.

This is the code of the page, I use jquery to make calls to other 2 pages that will yield me html.

<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Test.aspx.cs" Inherits="Solutions_CashCenter_StockManagement_Test_Test" %>
<asp:Content ID="Content2" ContentPlaceHolderID="cphCenter" Runat="Server">
<style type="text/css">
    #wait {
    position:absolute;
    top:0px;
    right:10px;
    width:200px;
    z-index:1000;
    vertical-align:middle;
    text-align:center;
    background: #febf00;
    display:none;
}
</style>
<script src='<%= ResolveUrl("../../../../Scripts/jquery-1.4.1.js") %>' type="text/javascript"></script>
<script type="text/javascript">
    $(function () {
        $('#wait')
        .ajaxStart(function () { $(this).show(); })
        .ajaxStop(function () { $(this).hide(); });

        $('input:button').live('click', loadData);
    });

    function loadData() {
        $.get("Source.aspx", {},
        function (data) {
            $('#a1').html(data);
        },
        "html");

        alert('This alert is asynchronous (1st)');

        $.get("Source2.aspx", {},
        function (data) {
            $('#a2').html(data);
        },
        "html");

        alert('This alert is asynchronous (2nd)');
    }
</script>
<div id="test13">
    <input type="button" id="btnLoad" value="Load" />
</div>
<div id="a1"></div>
<div id="a2"></div>
<div id="wait">Please wait <img src="ajax-loading.gif" /></div>
</asp:Content>

然后我有 2 个 aspx 页面,Source1.aspx 和 Source2.aspx.它们仅包含一个 gridDataView 和 OnLoad 事件中的少量代码.

Then I have 2 aspx pages, Source1.aspx and Source2.aspx. They only containe a gridDataView and little code in OnLoad event.

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Source.aspx.cs" Inherits="Solutions_CashCenter_StockManagement_Test_Source" %>
<form runat="server">
<cc1:GridDataView runat="server" ID="gridTest" >
</cc1:GridDataView>
<asp:SqlDataSource ID="dsTest" runat="server" ConnectionString="<%$ ConnectionStrings:WebPortalConnectionString %>"
    ProviderName="<%$ ConnectionStrings:WebPortalConnectionString.ProviderName %>">
</asp:SqlDataSource>
</form>

服务器端:

Thread.Sleep(5000);
dsTest.SelectCommand = "SELECT 'test1', 'test2', 'test3'";
this.gridTest.DataSourceID = "dsTest";
this.gridTest.DataBind();

第二页也一样,但网格的数据不同.

And the same for the second page, but with different data for the grid.

我得到的结果是两个警报同时发生,但是网格一个接一个地加载,即第一个网格在 5 秒后出现,然后第二个网格在 5 秒后出现.那就是服务器实际上并没有同时处理它们.

What I have in result is that both alerts happen at once, but the grids are loaded one after one, that is 1st grid appears after 5 seconds, and then second one appers after another 5 sec. That is the server does not actually process them concurrently.

我做错了什么,我应该如何组织所有人按我的需要工作?

What am I doing wrong and how should I organize all to work as I need?

推荐答案

这是因为会话锁定了页面读取.
因此,当一个页面正在加载时,会话会锁定所有其余请求,直到完成并发送页面.

This is happens because the session locks the page reads.
So when the one page is loading, the session lock all the rest request until is finish and send the page.

要使其正常工作,您需要 ether 禁用此页面上的会话,ether 使用默认情况下没有会话锁定的处理程序.

To make it work you need ether to disabled the session on this pages, ether use handler that is not have by default session lock.

相关问题:

尝试使 Web 方法异步
Web 应用程序在处理另一个 Web 应用程序时被阻止关于共享同一会话
哪些性能计数器可用于识别 ASP.NET 瓶颈?
完全替换 ASP.Net 的会话

这篇关于ASP.NET 服务器不异步处理页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆