本文分为前台和后台代码实现避免重复提交和弹出提示框效果,代码简单易懂,非常不错,具有参考借鉴价值,需要的的朋友参考下
前台代码:
<asp:Button ID="Button1" runat="server" Text="打印" onclick="Button1_Click" OnClientClick="this.value='数据提交中……';this.disabled=true;" UseSubmitBehavior="False" />
后台代码:
public partial class WebForm1 : System.Web.UI.Page
{
protected override void OnLoad(EventArgs e)
{
StringBuilder pageBase_script = new StringBuilder("<script Language=\"Javascript\">");
pageBase_script.Append(@"var times=0;
function pageBase_tick() //用于显示执行的时长
{
times++;
var str = '';
var temp = times%5;
for(var i=0;i<temp;i++)
str+='.';
document.getElementById('pageBase_Clocktimes').innerHTML ='正在提交,请稍候'+ str;
} "
);
pageBase_script.Append("<").Append("/").Append("script>");
StringBuilder pageBase_div = new StringBuilder(" <div id=\"pageBase_runing\" runat=\"server\" style=\"z-index: 12000; left: 0px; width: 100%; position: absolute; top: 0px; height: 100%\">");
pageBase_div.Append("<table width=\"100%\" height=\"100%\">");
pageBase_div.Append("<tr align=\"center\" valign=\"middle\">");
pageBase_div.Append("<td>");
pageBase_div.Append(" <table width=\"200\" height=\"25\" bgcolor=\"#9999FF\" style=\"filter: Alpha(Opacity=70); \">");
pageBase_div.Append(" <tr align=\"center\" valign=\"middle\">");
pageBase_div.Append(" <td>");
pageBase_div.Append("<div style=\"width:200px;height:25px; background-color: #99CCFF; \">");
pageBase_div.Append(" <div id=\"pageBase_Clocktimes\" style=\"color: #FF0000; float:left; width:196px;height:21px \" >正在提交,请稍候</div>");
pageBase_div.Append("</div>");
pageBase_div.Append("</td>");
pageBase_div.Append(" </tr>");
pageBase_div.Append(" </table>");
pageBase_div.Append(" </td>");
pageBase_div.Append(" </tr>");
pageBase_div.Append(" </table>");
pageBase_div.Append("</div>");
StringBuilder pageBase_divHide = new StringBuilder("<script Language=\"Javascript\">");
pageBase_divHide.Append("document.getElementById('pageBase_runing').style.visibility = \"hidden\";");
pageBase_divHide.Append("<").Append("/").Append("script>");
if (!Page.ClientScript.IsStartupScriptRegistered("runingscript"))
{
Page.ClientScript.RegisterStartupScript(Page.GetType(), "pageBase_div", pageBase_div.ToString());
Page.ClientScript.RegisterStartupScript(Page.GetType(), "pageBase_script", pageBase_script.ToString());
Page.ClientScript.RegisterStartupScript(Page.GetType(), "pageBase_divHide", pageBase_divHide.ToString());
}
base.OnLoad(e);
}
/// <summary>
/// 设置提交之后.出现请等待提示,在页面调用基类的这个方法,把要提交的控件传入即可
/// </summary>
/// <param name="btn">提交按钮</param>
public void SubmitLoad(Button btn)
{
btn.Attributes.Add("onclick", "javascript:document.getElementById('pageBase_runing').style.visibility='visible';window.setInterval('pageBase_tick()',500);");
}
/// <summary>
/// 设置提交之后.出现请等待提示
/// </summary>
/// <param name="lbtn">提交按钮</param>
public void SubmitLoad(LinkButton lbtn)
{
lbtn.Attributes.Add("onclick",
"javascript:document.getElementById('pageBase_runing').style.visibility='visible';window.setInterval('pageBase_tick()',1000);");
}
protected void Page_Load(object sender, EventArgs e)
{
SubmitLoad(Button1);
}
protected void Button1_Click(object sender, EventArgs e)
{
Button1.Enabled=false;
//string IP = PrintingLabel.SearchPrinterIP(TextBox1.Text, TextBox2.Text, TextBox3.Text);
//Response.Write(IP);
int ifs=0;
for (int i = 0; i < 1000000000; i++)
{
ifs++;
}
}
}
}
以上所述是小编给大家介绍的asp.net中避免重复提交和弹出提示框的实例代码,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对编程学习网网站的支持!
沃梦达教程
本文标题为:Asp.Net中避免重复提交和弹出提示框的实例代码
基础教程推荐
猜你喜欢
- C# 调用WebService的方法 2023-03-09
- C#类和结构详解 2023-05-30
- C# List实现行转列的通用方案 2022-11-02
- C# windows语音识别与朗读实例 2023-04-27
- winform把Office转成PDF文件 2023-06-14
- 一个读写csv文件的C#类 2022-11-06
- unity实现动态排行榜 2023-04-27
- ZooKeeper的安装及部署教程 2023-01-22
- linux – 如何在Debian Jessie中安装dotnet core sdk 2023-09-26
- C#控制台实现飞行棋小游戏 2023-04-22