【asp.net 】使用js结合hidden控件实现在后台运行一段程序后提示确认,确认通过后继续执行后台代码~~~
2009-05-21 14:53
1476 查看
后台代码:
前台代码:
using System; using System.Data; using System.Configuration; 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.Data.SqlClient; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { Label1.Text = ""; } protected void Button1_Click(object sender, EventArgs e) { string text = TextBox1.Text; if (Hidden1.Value == "1") { if (returnString("insert into student select '" + text + "'") == "1") { Label1.Text = text + "保存成功"; } else { Label1.Text = text + "保存失敗"; } Hidden1.Value = "0"; TextBox1.Text = ""; } else { string tt = ""; if (text.Trim() == "") { tt = "alert('不要提交空值!')"; } else { DataSet ds = new DataSet(); ds = returnDS("select count(1) from student where username='" + text + "'"); string content = text + "在資料庫中的個數為:" + ds.Tables[0].Rows[0][0].ToString() + ",確定保存?"; tt = "var rs=window.confirm(/" " + content + " /");"; tt += "if(rs){document.getElementById(/"" + Hidden1.ClientID + "/").value=/"1/";document.getElementById(/"" + Button1.ClientID + "/").click(); }else{ };"; } this.Page.RegisterStartupScript("aa", "<mce:script ><!-- " + tt + " // --></mce:script>"); } } public DataSet returnDS(string sql) { string connstr = "Data Source=xxxx;initial catalog=xxxx;user id=xxxx;password=xxxx"; SqlConnection myconn = new SqlConnection(connstr); myconn.Open(); SqlCommand mycomm = new SqlCommand(); mycomm.Connection = myconn; mycomm.CommandText = sql; mycomm.CommandType = CommandType.Text; SqlDataAdapter da = new SqlDataAdapter(mycomm); DataSet ds = new DataSet(); da.Fill(ds, "table"); myconn.Close(); return ds; } public string returnString(string sql) { try { string connstr = "Data Source=xxxx;initial catalog=xxxx;user id=xxxx;password=xxxx"; SqlConnection myconn = new SqlConnection(connstr); myconn.Open(); SqlCommand mycomm = new SqlCommand(); mycomm.Connection = myconn; mycomm.CommandText = sql; mycomm.CommandType = CommandType.Text; mycomm.ExecuteNonQuery(); myconn.Close(); return "1"; } catch (Exception ex) { return "2"; } } }
前台代码:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_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> </head> <body> <form id="form1" runat="server"> <div> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" /> <input id="Hidden1" runat="server" style="width: 14px" type="hidden" /> <asp:Label ID="Label1" runat="server"></asp:Label></div> </form> <div id="aa"></div> </body> </html>
相关文章推荐
- ASP.NET在后台代码实现个功能,根据选择提示用户是否继续执行操作
- 每日学习心得:CustomValidator验证控件验证用户输入的字符长度、Linq 多字段分组统计、ASP.NET后台弹出confirm对话框,然后点击确定,执行一段代码
- ASP.NET中服务器控件Button调用javascript代码运用正则表达式验证TextBox中输入的是否为正整数或正小数,符合要求则继续运行服务器端代码功能的实现
- 每日学习心得:CustomValidator验证控件验证用户输入的字符长度、Linq 多字段分组统计、ASP.NET后台弹出confirm对话框,然后点击确定,执行一段代码
- 每日学习心得:CustomValidator验证控件验证用户输入的字符长度、Linq 多字段分组统计、ASP.NET后台弹出confirm对话框,然后点击确定,执行一段代码
- ASP.NET 用户控件实现后台确认提醒框
- 在ASP.NET使用JavaScript显示信息提示窗口实现原理及代码
- 类似msn的提示效果代码系列三:脚本消息提示类和asp.net后台代码的结合
- ASP.NET通过Global.asax和Timer定时器 定时调用WebService 运行后台代码
- ASP.NET - 服务器控件button 先执行js 再执行后台的方法
- 使用ASP.NET一般处理程序或WebService返回JSON的实现代码
- ASP.NET后台执行JS代码
- 【C#】对异步请求处理程序IHttpAsyncHandler的理解和分享一个易用性封装 【手记】走近科学之为什么明明实现了IEnumerable<T>的类型却不能调用LINQ扩展方法 【手记】手机网页弹出层后屏蔽底层的滑动响应 【手记】ASP.NET提示“未能创建类型”处理 【Web】一个非常简单的移动web消息框 【手记】解决EXCEL跑SQL遇“查询无法运行或数据库表无法打开...”
- SVN 导出代码在VS2012运行提示“未能将网站xx 配置为使用 ASP.NET 4.0,为了使此网站正确运行,您必须将它手动配置为使用 ASP.NET 4.0”
- Linux使用screen实现关闭ssh连接的情况下,让程序继续在后台运行
- 让服务器控件执行js与C#两种代码(asp.net)
- 使用ASP.NET的C#语言写后台如何将数据返回给微信小程序的JS
- asp.net 在使用母版页的子页面cs后台代码中控制母版页中的登录控件显示
- ASP.NET通过Global.asax和Timer定时器 定时调用WebService 运行后台代码
- 解决调试asp.net程序时无法修改代码的问题(提示: 当调试器已经附加到已经运行的进程...)