using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml;
using System.Xml.XPath;namespace xmlTest
{
    public partial class _Default : System.Web.UI.Page
    {
        const string XMLFILE="~/xmlTest.xml";
        protected void Page_Load(object sender, EventArgs e)
        {
            XmlTextReader xmlRead = new XmlTextReader(Server.MapPath(XMLFILE));
            while (xmlRead.Read())
            {
                if (xmlRead.NodeType == XmlNodeType.Element)
                {
                    switch (xmlRead.Name)
                    {
                        case "Form":
                            //实现一些费时的操作,先模拟,System.Threading.Thread.Sleep(1000);                            break;
                        case "Input":
                            break;
                    }
                }
            }        }
    }
}
要求:出来一个loading...的图片(在执行load函数时,希望有高手,给个例子也行

解决方案 »

  1.   

    createMask();
    function createMask()

        document.write("<div id='shield'  style='Z-INDEX:1000;filter:alpha(opacity=10);BACKGROUND-COLOR:#cccccc;LEFT:0;WIDTH:100%;POSITION:absolute;TOP:0;HEIGHT:100%'><br>&nbsp;&nbsp;&nbsp;<img src='images/loading.gif'>数据正在读入中,请稍等...</div>");

    document.onreadystatechange = new Function("hiddenLay();");
    function hiddenLay()
    {
    if(document.readyState=="complete")
    {
         document.getElementById("shield").style.display="none";
    }
    }
    存成js,再head里引用就可以了
      

  2.   

    http://www.cnblogs.com/stg609/archive/2008/08/04/1259469.html 
    去看看这个博客吧! 
    也许有你要的东西! 
    这个用的是Ajax.
      

  3.   

    <div id="doing" runat="server" style="Z-INDEX: 12000; LEFT: 0px; WIDTH: 100%; CURSOR: wait; POSITION: absolute; TOP: 0px; HEIGHT: 100%"> 
    <table width="100%" height="100%"> 
    <tr align="center" valign="middle"> 
    <td> 
    <table width="169" height="62" bgcolor="#99cccc" style="FILTER: Alpha(Opacity=75); WIDTH: 169px; HEIGHT: 62px"> 
    <tr align="center" valign="middle"> 
    <td>页面提交中.<br> 
    Loading.</td> 
    </tr> 
    </table> 
    </td> 
    </tr> 
    </table> 
    </div>
    <asp:Button ID="Button1" runat="server" Text="Button" />    protected void Page_Load(object sender, EventArgs e)
        {
            this.Button1.Attributes.Add("onclick", "javascript:document.getElementById('doing').style.visibility='visible';");
            for (int i = 0; i < 10; i++)
            {
                System.Threading.Thread.Sleep(1000);
            }
        }    override protected void OnPreRender(EventArgs e)
        {
            doing.Style.Add("visibility", "hidden");
        } 
      

  4.   

    代码报错。PreRender时控件还没注册?
      

  5.   

    没错,用ajax的,怎么用?2楼的意思我明白。好像少了代码
      

  6.   

    你不需要写调用代码
    document.onreadystatechange 事件给加好了,加载完成自动清空上面的显示层
      

  7.   


    大哥..这只能用于IE..在FF下不行...一直显示着..求解..
      

  8.   

    给个我以前写的,但是这个是简化版。而且进度条是虚拟的。要时时到3楼去看看吧!!
    主要是实现页面上那层透明膜的出来和消失。function ModalDialog(name,divid,width,height,leftop,topop,color)
       {
           this.name=name;//名称
           this.div=divid;//要放入窗体中的元素名称
           this.width=width;//窗体宽
           this.height=height;//窗体高
           this.leftop=leftop;//左侧位置
           this.topop=topop;//上部位置
           this.color=color;//整体颜色
           this.show=function()//显示窗体
           {
               document.all(obj.name+"_divshow").style.width=obj.width;
               document.all(obj.name+"_divshow").style.height=obj.height;
               document.all(obj.name+"_divshow").style.left=obj.leftop;
               document.all(obj.name+"_divshow").style.top=obj.topop;
               document.all(obj.name+"_mask").style.width=document.body.clientWidth;
               document.all(obj.name+"_mask").style.height=document.body.clientHeight;
               document.all(obj.name+"_divshow").style.visibility="visible";
               document.all(obj.name+"_mask").style.visibility="visible";
           }
           
           this.close=function()//关闭窗体
           {  
               document.all(obj.name+"_divshow").style.width=0;
               document.all(obj.name+"_divshow").style.height=0;
               document.all(obj.name+"_divshow").style.left=0;
               document.all(obj.name+"_divshow").style.top=0;
               document.all(obj.name+"_mask").style.width=0;
               document.all(obj.name+"_mask").style.height=0;
               document.all(obj.name+"_divshow").style.visibility="hidden";
               document.all(obj.name+"_mask").style.visibility="hidden";         
           }
            var obj=this;
       }页面<html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>无标题页</title>
        <script type="text/javascript" src="Admin_Scripts/ModalDialog.js"></script>
        <script language="javascript">    var md=new ModalDialog("md","iframe",400,100,100,100,"#ffffff");    //显示注册窗口
        function uRegShow()
        {
            md.show();
            return false;
        }    function uCloseShow()
        {
            md.close();
            return false;
        }    function CheckValid()
        {
            uRegShow();
            return true;
        }    </script>
    </head>
    <body style="width:600px; height:600px;">
        <form id="form1" runat="server">
        <div>
            <asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="return checkUploadFileName();" />
        </div>
         <div id ="div_Loading">
            <div id='md_divshow' style='position:absolute; left:0; top:0;z-index:10; visibility:hidden;width:0;height:0'>
                <table cellpadding='0' cellspacing='0' border='0' width=100% height=100% >
                    <tr>
                        <td id='md_content' valign='top' >
                            <div id="iframe"  style="border: solid 1px #ccc">
                                <div id="progress" runat="server">
                                </div>
                            </div>
                        </td>
                    </tr>
                </table>
            </div>
            <div  id='md_mask' style='position:absolute; top:0; left:0; width:0; height:0; background:#666; filter:ALPHA(opacity=50); z-index:9; visibility:hidden'></div>
        </div>
        </form>
    </body>
    </html>
    <script type="text/javascript">
        function checkUploadFileName()
        {  
           
                 CheckValid();
              
                return true;
        }
    </script>后台代码:protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                //高裕金添加。日期:2009/01/09 Start
                //把UploadFile.aspx页面,添加到New.aspx中。
                progress.InnerHtml = "<iframe id='IFpage' width='100%' height='100%' scrolling=no frameborder='0' src='UploadFile.aspx' onload = 'reSetIframe()'></iframe>";
                //高裕金添加。日期:2009/01/09 end
            }
        }进度条:<html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>文件上传中...</title>
        <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=gb2312">
    </head>
    <body BGCOLOR="#EAEAEA">
        <form name ="loading">
          <table border="0" cellpadding="0" cellspacing="0" width="100%" height="100%">
           <TD align="center" valign="top">
           <p><FONT color="black" face="Arial"><BR>
              文件上传中,请等待...</FONT></p>
           <p><input type="text"  name="chart" size="46" style="font-family:Arial;  font-weight:bolder; color:black; background-color:#EAEAEA; padding:0px; border-style:none;">
            <br>
            <input type="text" name="percent" size="46" style="font-family:Arial;  color:black; background-color:#EAEAEA;text-align:center; border-width:medium; border-style:none;">
            <script>var bar = 0
            var line = "||"
            var amount ="||"
            count()
            function count(){
            bar= bar+2
            amount =amount + line
            document.loading.chart.value=amount
            document.loading.percent.value=bar+"%"
            if (bar<99)
            {setTimeout("count()",1000);}
            else
            {window.location = "UploadFile.aspx";}
            }
            </script></p></TD>
            </tr>
            </table>
        </form>
    </body>
    </html>
      

  9.   


    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.Xml;
    using System.Xml.XPath;namespace xmlTest
    {
        public partial class _Default : System.Web.UI.Page
        {
            const string XMLFILE="~/xmlTest.xml";
            private Label NewRequired()
            {
                Label lblStar = new Label();
                lblStar.Text = "*";
                lblStar.ForeColor = System.Drawing.Color.Red;
                return lblStar;        }
            private RequiredFieldValidator NewRequiredValldator(string strControlName)
            {
                RequiredFieldValidator validator = new RequiredFieldValidator();
                validator.ControlToValidate = strControlName;
                validator.Text="Required";
                return validator;
            }        protected void BtnValidate_Click(object sender, EventArgs e)
            {
                Page.Validate();
            }
            protected void BtnSubmit_Click(object sender, EventArgs e)
            {
                txtResult.Text = string.Empty;
                foreach (TableRow row in formTable.Rows)
                {
                    foreach (TableCell cell in row.Cells)
                    {
                        foreach(Control c in cell.Controls)
                        {
                            if (c.GetType() == (new Label()).GetType())
                            {
                                Label l = (Label)cell.Controls[0];
                                if(l.Text!="*")
                                     txtResult.Text += l.Text + "=";
                            }
                            if (c.GetType() == (new TextBox()).GetType())
                            {
                                TextBox t = (TextBox)cell.Controls[0];
                                txtResult.Text += t.Text + "\r\n";
                            }
                        }
                                       }
                }
            }
            protected void Page_Load(object sender, EventArgs e)
            {
                if (!Page.IsPostBack)   //这个不行?
                {
                    string strText = string.Empty;
                    string strName = string.Empty;
                    string strType = string.Empty;
                    string strRequired = string.Empty;
                    XmlTextReader xmlRead = new XmlTextReader(Server.MapPath(XMLFILE));                while (xmlRead.Read())
                    {
                        if (xmlRead.NodeType == XmlNodeType.Element)
                        {
                            switch (xmlRead.Name)
                            {
                                case "Form":
                                    Page.Title = xmlRead.GetAttribute("Title");
                                    break;
                                case "Input":
                                    strText = xmlRead.GetAttribute("Text");
                                    strName = xmlRead.GetAttribute("Name");
                                    strType = xmlRead.GetAttribute("Type");
                                    strRequired = xmlRead.GetAttribute("Required");
                                    switch (strType)
                                    {
                                        case "TextBox":
                                            TextBox control = new TextBox();
                                            if (strName != string.Empty)
                                                control.ID = strName;
                                            Label lblTextBox = new Label();
                                            lblTextBox.Text = strText;
                                            TableRow row = new TableRow();
                                            TableCell cell1 = new TableCell();
                                            cell1.Controls.Add(lblTextBox);
                                            if (strRequired == "true" && !Page.IsPostBack)
                                            {
                                                cell1.Controls.Add(NewRequired());
                                            }
                                            TableCell cell2 = new TableCell();
                                            cell2.Controls.Add(control);
                                            row.Cells.Add(cell1);
                                            row.Cells.Add(cell2);
                                            if (strRequired == "true" && !Page.IsPostBack)
                                            {
                                                cell2.Controls.Add(NewRequiredValldator(strName));
                                            }
                                            formTable.Rows.Add(row);
                                            break;
                                        case "Button":
                                            Button btn = new Button();
                                            btn.Text = strText;
                                            if (strName != string.Empty)
                                                btn.ID = strName;
                                            TableRow row1 = new TableRow();
                                            TableCell cellButton = new TableCell();
                                            cellButton.ColumnSpan = 2;
                                            cellButton.Controls.Add(btn);
                                            row1.Cells.Add(cellButton);                                        formTable.Rows.Add(row1);
                                            switch (strText)
                                            {
                                                case "Commit":
                                                    btn.Click += new EventHandler(BtnSubmit_Click);
                                                    btn.UseSubmitBehavior = true;
                                                    break;
                                                case "Validate":
                                                    btn.Click += new EventHandler(BtnValidate_Click);
                                                    btn.UseSubmitBehavior = false;
                                                    break;
                                            }
                                            break;
                                    }
                                    break;
                            }
                        }
                    }
                    xmlRead.Close();
                }
            }
        }
    }为什么不能加postpack?加了就显示不出textbox了
      

  10.   

    Default.aspx<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="xmlTest._Default" %><!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">
        <title>Untitled Page</title>
        <style type="text/css">
        .tableLine
        {
        border-collapse: collapse;
        border-style: solid;
        border-width: 1px;
        }
        </style></head>
    <body>
        <form id="form1" runat="server">
            <asp:ScriptManager ID="ScriptManager1" runat="server" />
         
            <asp:Table ID="formTable" runat="server" CssClass="tableLine" >
            </asp:Table>
         
            <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
                <ContentTemplate>
                    <asp:TextBox ID="txtResult" runat="server" Height="285px" ReadOnly="True" 
                        Width="305px" TextMode="MultiLine"></asp:TextBox>
                </ContentTemplate>
            </asp:UpdatePanel>
        </form>
    </body>
    </html>
      

  11.   

    xmlTest.xml<?xml version="1.0" encoding="utf-8" ?>
    <Form Title="testForm">
      <Input Text="ID" Name="txtID" Type="TextBox" Required="true"></Input>
      <Input Text="Name" Name="txtName" Type="TextBox" Required="true"></Input>
      <Input Text="Job" Name="txtJob" Type="TextBox" Required="false"></Input>
      <Input Text="Validate" Name="btnValidate" Type="Button"></Input>
      <Input Text="Commit" Name="btnComit" Type="Button"></Input>
    </Form>
      

  12.   

    改了一下兼容FF
    <script>
    createMask();
    function createMask()

        document.write("<div id='shield'  style='Z-INDEX:1000;filter:alpha(opacity=10);BACKGROUND-COLOR:#cccccc;LEFT:0;WIDTH:100%;POSITION:absolute;TOP:0;HEIGHT:100%'><br>&nbsp;&nbsp;&nbsp;<img src='images/loading.gif'>数据正在读入中,请稍等...</div>");
    } if(document.addEventListener)//FF
    {
        document.addEventListener("DOMContentLoaded",hiddenLay,null);
    }else
    {
        document.onreadystatechange=function()
        {
            
            hiddenLay(1);
        }
    }function hiddenLay()
    {     if(arguments[0]!=1||document.readyState=="complete")
         {
            document.getElementById("shield").style.display="none";
         }
    }
    </script>
      

  13.   

    代码下载
    http://conan19771130.download.csdn.net/
      

  14.   

    有高手吗?用动态绑定,为什么提交后要重新绑定?添到controls也没用
      

  15.   

    楼主,你的代码要给几个关键注释行吗??
    不然看的很累,也懒的看了!

    我也是刚学习的Ajax,所以粗看了下代码-->
    你是要动态的在formTable中加控件元素,用的是局部刷新!
    但是,你有没有把formTable元素放进UpdatePanel 中,
    所以好像formTable的东西加了postpack以后就不会刷新了!!
    你把formTable放进UpdatePanel试一下!!!
    我刚看 Ajax ,如果有啥错误的请指教!!