近来有用户反映系统老是重复添加记录,一查,原因是用户在提交数据的时候,浏览器反应较慢,用户误以为程序停止,于是再次点击提交按钮,于是问题出现.
于是想到一种办法,在用户提交数据之后,当前网页最顶端显示一个透明的大小和当前浏览器客户区域同等的DIV,提示用户当前操作正在进行. 如此,用户会看到数据执行过程,就不会再次提交.
时间仓促,代码公布如下,有几处属性需要添加设计师支持. 来日有时间再完善.
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
Code
1
using System;
2
using System.Collections.Generic;
3
using System.ComponentModel;
4
using System.Linq;
5
using System.Text;
6
using System.Web;
7
using System.Web.UI;
8
using System.Web.UI.WebControls;
9
using System.Drawing;
10
using System.Security.Permissions;
11
namespace Loading
12![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
{
13
[ToolboxData("<{0}:DongLoading runat=server></{0}:DongLoading>")]
14
[Localizable(true)]
15
public class DongLoading : WebControl
16![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
17
private string imagePath = "1";
18
private string backColor = "AliceBlue";
19
private string targetControlID = string.Empty;
20
//private Color dongBorderColor;
21![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
22
[Category("DongUI"), TypeConverter(typeof(WebColorConverter)), DefaultValue(typeof(Color), ""), NotifyParentProperty(true)]
23
public Color DongBorderColor
24![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
25
get
26![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
27
return (Color)this.ViewState["DongBorderColor"];
28
}
29
set
30![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
31
this.ViewState["DongBorderColor"] = value;
32
}
33
}
34![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
35![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
36![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
37![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
Property#region Property
38
[Category("DongUI"), Description("指定做为进度提示的背景透明图片的路径"),Browsable(true)]
39
public string ImagePath
40![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
41![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
get
{ return this.imagePath; }
42
set
43![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
44
imagePath = value;
45
}
46
}
47![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
48
[Category("DongUI")]
49
[Description("指定背景颜色")]
50
[Browsable(true)]
51
public string BackColor
52![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
53![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
get
{ return this.backColor; }
54
set
55![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
56
backColor = value;
57
}
58
}
59![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
60
[Category("DongUI")]
61
[Description("指定目标控件")]
62
[Browsable(true), TypeConverter(typeof(ControlIDConverter)), DefaultValue(typeof(Button), null)]
63
public string TargetControlID
64![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
65![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
get
{ return this.ViewState["TargetControlID"].ToString(); }
66
set
67![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
68
ViewState["TargetControlID"] = value;
69
}
70
}
71
#endregion
72![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
73![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
override#region override
74![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
75
/// Renders the contents.
76
/// </summary>
77
/// <param name="output">The output.</param>
78
protected override void RenderContents(HtmlTextWriter output)
79![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
80
// 隐藏透明面板
81
output.Write("<script> window.document.all." + this.ClientID + ".style.display=\"none\";</script>");
82
}
83![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
84![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
85
/// 将控件的 HTML 开始标记呈现到指定的编写器中。此方法主要由控件开发人员使用。
86
/// </summary>
87
/// <param name="writer"><see cref="T:System.Web.UI.HtmlTextWriter"/>,表示要在客户端呈现 HTML 内容的输出流。</param>
88
public override void RenderBeginTag(HtmlTextWriter writer)
89![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
90
string color = DongBorderColor.IsNamedColor == true ? DongBorderColor.Name : "#" + DongBorderColor.Name;
91
string html = "<div id=\"" + this.ClientID + "\" oncontextmenu=\"return false;\" style=\" left: 0;top: 0; position: absolute; width: expression( window.document.documentElement.offsetWidth );" +
92
" height: expression( window.document.documentElement.clientHeight > window.document.documentElement.scrollHeight ? window.document.documentElement.clientHeight : window.document.documentElement.scrollHeight ); " +
93
" z-index: 888; filter: progid:DXImageTransform.Microsoft.Alpha(opacity=80); display: inline; background-color: " + color + "\">";
94
html += " <img style=\" position: absolute;left: expression( document.documentElement.clientWidth / 2 - this.clientWidth / 2 ); top: expression( document.documentElement.clientHeight / 2 - this.clientHeight / 2 + document.documentElement.scrollTop ); \" src=\"" + ImagePath + "\">";
95
writer.Write(html);
96
}
97![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
98![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
99
/// 将控件的 HTML 结束标记呈现到指定的编写器中。此方法主要由控件开发人员使用。
100
/// </summary>
101
/// <param name="writer"><see cref="T:System.Web.UI.HtmlTextWriter"/>,表示要在客户端呈现 HTML 内容的输出流。</param>
102
public override void RenderEndTag(HtmlTextWriter writer)
103![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
104
if (Page != null)
105![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
106
string js = "window.document.all[\'" + this.ClientID + "\'].style.display=\'inline\'";
107
Button bt = this.Page.FindControl(TargetControlID) as Button;
108
bt.Attributes.Add("onclick", js);
109
}
110
writer.Write("</div>");
111
}
112
#endregion
113
}
114
}
115![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
效果:
![](https://images.cnblogs.com/cnblogs_com/juejue1984/149135/r_%e6%96%b0%e5%bb%ba%e4%bd%8d%e5%9b%be%e5%9b%be%e5%83%8f.png)
1 <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Loading.aspx.cs" Inherits="WebApplication1.Loading" %>
2 <%@ Register Assembly="Loading" Namespace="Loading" TagPrefix="cc1" %>
3 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
4 <html xmlns="http://www.w3.org/1999/xhtml">
5 <head runat="server">
6 <title>无标题页</title>
7 </head>
8 <body>
9 <form id="form1" runat="server">
10 <div style="height: 1316px">
11 <cc1:DongLoading ID="DongLoading1" runat="server" BackColor="Aliceblue" ImagePath="hi.gif"
12 TargetControlID="Button1" DongBorderColor="AliceBlue" />
13 <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
14 <div style="position:absolute; width:300px; height:1300px; border: solid 2px blue;"></div>
15 </div>
16 </form>
17 </body>
18 </html>