단추가있는 페이지가 있고 버튼을 눌러 비동기 적으로 데이터가있는 2 개의 데이터 표를로드하려고합니다.ASP.NET 서버가 페이지를 비동기 적으로 처리하지 않습니다.
이것은 페이지의 코드입니다. jquery를 사용하여 다른 2 페이지를 호출하여 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 이벤트에있는 작은 코드만을 포함하고 있습니다.
<%@ 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();
및 두 번째 페이지에 대해 동일하지만, 상이한 그리드 데이터.
두 결과는 한 번에 두 경고가 발생하지만 그리드가 하나씩로드되는 것입니다. 즉, 첫 번째 그리드가 5 초 후에 나타나고 두 번째 그리드가 5 초 후에 나타납니다. 서버가 실제로 처리하지 않습니다.
내가 뭘 잘못하고 필요한 모든 작업을 어떻게 구성해야합니까?
당신이 "페이지 로딩"에서 무엇을 의미합니까? 나는 페이지를로드하지 않았지만 아약스 요청을했습니다. –
@VitaliiKorsakov 아약스 요청은 클라이언트에서 비동기 적으로 페이지를로드하는 것입니다. 여전히 페이지를로드합니다. 클라이언트 브라우저가 아니라 서버에서 처리됩니다. 세션 잠금으로 인해 서버에서의 처리가 차단되었습니다. – Aristos
@VitaliiKorsakov이 페이지의 세션을 비활성화하면 예상대로 작동하는 것을 볼 수 있습니다. – Aristos