有人可以解释一下firefox updatepanel异步回发与IE中执行的回复之间的速度差异吗?
500个对象的平均Firefox回发时间:1.183秒
平均IE回发时间500个对象:0.295秒
使用firebug我可以看到FireFox中的大部分时间花在服务器端。总共1.04秒。
鉴于这一事实我唯一可以假设的是导致这个问题是ASP.Net在两个浏览器之间呈现控件的方式。
之前有没有人遇到这个问题?
VB.Net代码
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
GridView1.DataBind()
End Sub
Public Function GetStockList() As StockList
Dim res As New StockList
For l = 0 To 500
Dim x As New Stock With {.Description = "test", .ID = Guid.NewGuid}
res.Add(x)
Next
Return res
End Function
Public Class Stock
Private m_ID As Guid
Private m_Description As String
Public Sub New()
End Sub
Public Property ID() As Guid
Get
Return Me.m_ID
End Get
Set(ByVal value As Guid)
Me.m_ID = value
End Set
End Property
Public Property Description() As String
Get
Return Me.m_Description
End Get
Set(ByVal value As String)
Me.m_Description = value
End Set
End Property
End Class
Public Class StockList
Inherits List(Of Stock)
End Class
标记
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<script type="text/javascript" language="Javascript">
function timestamp_class(this_current_time, this_start_time, this_end_time, this_time_difference) {
this.this_current_time = this_current_time;
this.this_start_time = this_start_time;
this.this_end_time = this_end_time;
this.this_time_difference = this_time_difference;
this.GetCurrentTime = GetCurrentTime;
this.StartTiming = StartTiming;
this.EndTiming = EndTiming;
}
//Get current time from date timestamp
function GetCurrentTime() {
var my_current_timestamp;
my_current_timestamp = new Date(); //stamp current date & time
return my_current_timestamp.getTime();
}
//Stamp current time as start time and reset display textbox
function StartTiming() {
this.this_start_time = GetCurrentTime(); //stamp current time
}
//Stamp current time as stop time, compute elapsed time difference and display in textbox
function EndTiming() {
this.this_end_time = GetCurrentTime(); //stamp current time
this.this_time_difference = (this.this_end_time - this.this_start_time) / 1000; //compute elapsed time
return this.this_time_difference;
}
//-->
</script>
<script type="text/javascript" language="javascript">
var time_object = new timestamp_class(0, 0, 0, 0); //create new time object and initialize it
Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequestHandler);
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
function BeginRequestHandler(sender, args) {
var elem = args.get_postBackElement();
ActivateAlertDiv('visible', 'divAsyncRequestTimer', elem.value + '');
time_object.StartTiming();
}
function EndRequestHandler(sender, args) {
ActivateAlertDiv('visible', 'divAsyncRequestTimer', '(' + time_object.EndTiming() + ' Seconds)');
}
function ActivateAlertDiv(visstring, elem, msg) {
var adiv = $get(elem);
adiv.style.visibility = visstring;
adiv.innerHTML = msg;
}
</script>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Button1" EventName="click" />
</Triggers>
<ContentTemplate>
<asp:Button ID="Button1" runat="server" Text="Button" />
<div id="divAsyncRequestTimer" style="font-size:small;">
</div>
<asp:GridView ID="GridView1" runat="server" DataSourceID="ObjectDataSource1" AutoGenerateColumns="False">
<Columns>
<asp:BoundField DataField="ID" HeaderText="ID" SortExpression="ID" />
<asp:BoundField DataField="Description" HeaderText="Description"
SortExpression="Description" />
</Columns>
</asp:GridView>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
SelectMethod="GetStockList" TypeName="WebApplication1._Default">
</asp:ObjectDataSource>
</ContentTemplate>
</asp:UpdatePanel>
</form>
答案 0 :(得分:1)
我猜它是编译页面的初始时间。当我首先运行IE页面时,它会在一秒钟后渲染,然后在firefox中运行页面大约需要0.2秒。