Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 在页面加载完成之前显示图像/HTML_Asp.net_Vb.net - Fatal编程技术网

Asp.net 在页面加载完成之前显示图像/HTML

Asp.net 在页面加载完成之前显示图像/HTML,asp.net,vb.net,Asp.net,Vb.net,我在aspx中有以下代码 <%@ Page Language="VB" AutoEventWireup="false" CodeFile="test.aspx.vb" nherits="test" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html

我在aspx中有以下代码

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="test.aspx.vb" nherits="test" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server"></head>
    <body>
         <img src="images/loading_anim.gif" />Please wait...
      </body>
    </html>

代码隐藏我在Page_load方法中进行了一些处理并重定向到其他页面,但这可能需要一些时间,因此我希望显示用户加载图像。但这表明在Page_load完成后。如何处理此问题?

我认为它不会起作用,因为服务器端代码总是先工作,然后才开始HTML呈现。更好的选择是使用Ajax


这里有更多详细信息:

我建议您使用通用处理程序(ashx)并使用非缓冲响应。例如:

public class Handler : IHttpHandler 
{

    public void ProcessRequest (HttpContext context) 
    {
         context.Response.BufferOutput = false;
         context.Response.Write("<html><head></head><body><img src=\"images/loading_anim.gif\" />Please wait...</body></html>"  
         context.Response.Flush();  

         // do your processing
         ...
         // redirect 
    }
 ...
}
公共类处理程序:IHttpHandler
{
公共void ProcessRequest(HttpContext上下文)
{
context.Response.BufferOutput=false;
context.Response.Write(“请稍候…”
context.Response.Flush();
//做你的处理
...
//重定向
}
...
}
另一种方法是首先在客户端显示图像(使用java脚本),然后从客户端执行重定向(或post)

public class Handler : IHttpHandler 
{

    public void ProcessRequest (HttpContext context) 
    {
         context.Response.BufferOutput = false;
         context.Response.Write("<html><head></head><body><img src=\"images/loading_anim.gif\" />Please wait...</body></html>"  
         context.Response.Flush();  

         // do your processing
         ...
         // redirect 
    }
 ...
}