无为清净楼资源网 Design By www.qnjia.com
.aspx:
<%@ 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>无标题页</title> <script type="text/javascript"> //向服务器传递参数 function DoSearch(){ var firstName=document.getElementById("TextBox1").value; CallServer(firstName,""); } //得到服务器的数据 function ReceiveServerData(txtUserInfo){ Results.innerHTML=txtUserInfo; } //设置每1秒执行一次 setInterval("DoSearch()",1000); </script> </head> <body> <form id="form1" runat="server"> <div> 姓名:<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <br /> <span id="Results" style=" width:500px;"></span> </div> </form> </body> </html> [/code] .aspx.cs [code] using System; using System.Collections; using System.Configuration; using System.Data; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Data.SqlClient; public partial class _Default : System.Web.UI.Page, ICallbackEventHandler { protected string txtUserInfo; protected void Page_Load(object sender, EventArgs e) { //获取一个对客户端函数的引用 string cbReference = Page.ClientScript.GetCallbackEventReference(this, "arg", "ReceiveServerData", "context"); //动态注册回调函数 string callbackScript = "function CallServer(arg,context)" + "{" + cbReference + "};"; //引发callbackScript Page.ClientScript.RegisterStartupScript(this.GetType(), "CallServer", callbackScript, true); } //引发Callback事件处理 public void RaiseCallbackEvent(string txtFirstName) { if (txtFirstName != null) { String connString = System.Configuration.ConfigurationManager.ConnectionStrings["sqlserver2008"].ToString(); SqlConnection conn = new SqlConnection(connString); conn.Open(); SqlCommand comm = new SqlCommand("select * from zzx where [name]=@name", conn); comm.Parameters.Add("@name", SqlDbType.VarChar).Value = txtFirstName; SqlDataReader reader = comm.ExecuteReader(CommandBehavior.CloseConnection); if (reader.Read()) { txtUserInfo = "员工编号:" + reader["id"].ToString() + "<br>"; txtUserInfo += "员工姓名:" + reader["name"].ToString() + "<br>"; txtUserInfo += "地址:" + reader["address"].ToString() + "<br>"; txtUserInfo += "服务器查询时间:" + DateTime.Now.ToString(); } else { if (string.IsNullOrEmpty(txtFirstName)) { txtUserInfo = "请输入姓名"; } else { txtUserInfo = "查无此人"; } } comm.Dispose(); reader.Dispose(); conn.Dispose(); } } //得到回调的结果,返回给客户端 public string GetCallbackResult() { return txtUserInfo; } }
简化版(偷懒一下):
<%@ 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>无标题页</title> <script type="text/javascript"> function OnCallBack(txtUserInfo,context){ Results.innerHTML=txtUserInfo; } </script> </head> <body> <form id="form1" runat="server"> <div> 姓名:<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <input id="Button2" type="button" value="button" onclick="<%=Page.ClientScript.GetCallbackEventReference(this, "document.getElementById('TextBox1').value", "OnCallBack",null)%>" /> <br /> <span id="Results" style="pink; width: 500;"></span> </div> </form> </body> </html> .aspx.cs using System; using System.Collections; using System.Configuration; using System.Data; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Data.SqlClient; using System.Text; public partial class _Default : System.Web.UI.Page, ICallbackEventHandler { protected StringBuilder txtUserInfo; protected void Page_Load(object sender, EventArgs e) { } public string GetCallbackResult() { return txtUserInfo.ToString(); } public void RaiseCallbackEvent(string txtFirstName) { txtUserInfo = new StringBuilder(); String connString = ConfigurationManager.ConnectionStrings["sqlserver2008"].ToString(); SqlConnection conn = new SqlConnection(connString); conn.Open(); SqlCommand comm = new SqlCommand("select * from zzx where [name]=@name", conn); comm.Parameters.Add("@name", SqlDbType.VarChar).Value = txtFirstName; SqlDataReader reader = comm.ExecuteReader(CommandBehavior.CloseConnection); if (reader.Read()) { txtUserInfo.Append("员工编号:" + reader["id"].ToString() + "<br>"); txtUserInfo.Append("员工姓名:" + reader["name"].ToString() + "<br>"); txtUserInfo.Append("地址:" + reader["address"].ToString() + "<br>"); txtUserInfo.Append("查询时间:" + DateTime.Now.ToString()); } else { if (txtFirstName == string.Empty) { txtUserInfo.Append("请输入姓名"); } else { txtUserInfo.Append("查无此人"); } reader.Dispose(); comm.Dispose(); conn.Dispose(); } } }
示例3:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %> <!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>无标题页</title> <script type="text/javascript"> //客户端执行的方法 //下面的方法是接收并处理服务器方法返回的结果 function Success(args,context){ message.innerHTML=args; } //下面的方式是当接收服务器方法处理的结果发生异常时调用的方法 function Error(){ message.innerHTML="发生了异常!"; } </script> </head> <body> <form id="form1" runat="server"> <div> 用户名:<input type="text" id="txtUserName" onblur="CallServerMethod(txtUserName.value,null)" /> <span id="message"></span> <br /> 密码:<input type="password" size="10" maxlength="20" id="txtPwd" /> </div> </form> </body> </html> [code] public partial class Default3 : System.Web.UI.Page,ICallbackEventHandler //实现ICallbackEventHandler接口 { String result = String.Empty; protected void Page_Load(object sender, EventArgs e) { //获取当前页的ClientScriptManager的引用 ClientScriptManager csm = Page.ClientScript; /*获取回调的引用.会在客户端生成WebForm_DoCallback方法, * 调用它来达到异步调用.这个方法是微软写的方法,会被发送 到客户端*/ /*注意这里的"Success"和Error两个字符串分别是客户端代码中 *定义的两个javascript函数*/ //下面的方法最后一个参数的意义:true表示执行异步回调,false标志执行同步回调 String reference = csm.GetCallbackEventReference(this, "args", "Success", "", "Error", true); String callbackScript = "function CallServerMethod(args,context){\n"+ reference+";\n }"; //向当前页面注册javascript脚本代码 csm.RegisterClientScriptBlock(this.GetType(), "CallServerMethod",callbackScript,true); } #region ICallbackEventHandler 成员 /// <summary> /// 返回回调方法执行结果的方法 /// </summary> public string GetCallbackResult() { return result; } /// <summary> /// 在服务器端运行回调方法 /// </summary> public void RaiseCallbackEvent(string eventArgument) { if (eventArgument.ToLower().IndexOf("admin")!=-1) { result =eventArgument+ "不能作为用户注册."; } else { result = eventArgument + "可以注册."; } } #endregion }
无为清净楼资源网 Design By www.qnjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
无为清净楼资源网 Design By www.qnjia.com
暂无评论...
P70系列延期,华为新旗舰将在下月发布
3月20日消息,近期博主@数码闲聊站 透露,原定三月份发布的华为新旗舰P70系列延期发布,预计4月份上市。
而博主@定焦数码 爆料,华为的P70系列在定位上已经超过了Mate60,成为了重要的旗舰系列之一。它肩负着重返影像领域顶尖的使命。那么这次P70会带来哪些令人惊艳的创新呢?
根据目前爆料的消息来看,华为P70系列将推出三个版本,其中P70和P70 Pro采用了三角形的摄像头模组设计,而P70 Art则采用了与上一代P60 Art相似的不规则形状设计。这样的外观是否好看见仁见智,但辨识度绝对拉满。
更新日志
2024年10月10日
2024年10月10日
- 谢金燕.2004-默契【华特】【WAV+CUE】
- 《蛋仔派对》锤头鲨皮肤图鉴
- 《蛋仔派对》瞌睡羊皮肤图鉴
- 《蛋仔派对》活力橙皮肤图鉴
- 马常胜《古琴韵》限量1:1母盘直刻[低速原抓WAV+CUE]
- 苗苗《民歌红·湘女多情》纯银CD[低速原抓WAV+CUE]
- 马小倩《落花A2HD3-HQCD》头版限量[低速原抓WAV+CUE]
- 343前动画师怒喷343糟糕管理层:纯纯的毒瘤
- 《生化2RE》12.31苹果Mac平台发售:现已登陆商店
- 《使命召唤21:黑色行动6》实机发售预告!体验史诗电影单人战役
- 《张雨生 不朽的歌声 黑胶2CD》[WAV/分轨][860MB]
- 《赵传 你过得还好吗 2017》[FLAC/分轨][350MB]
- 《流行新歌告诉你 36首经典金曲 2CD》[WAV+CUE][1GB]
- 王宏伟.2012-用我的心握你的手【太平洋影音】【WAV+CUE】
- 谢安琪.2006-K.SUS.2(EP)(2015金碟复刻版)【BanBanMusic】【WAV+CUE】