环境Win7,VS2008(sp1),SQL2008Express.
public void RaiseCallbackEvent(string txtFirstName) {....} 不会运行到这个方法.
代码如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ClientCallbacks.aspx.cs" Inherits="ClientCallbacks" %><!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 txtFirstName = document.getElementById("txtUserName");
CallServer(txtFirstName.value, '');
Results.innerText = txtFirstName.value;
Span1.innerText = "1";
Span2.innerText = "2";
Span3.innerText = "3";
} function ReceiveServerData(txtUserInfo)
{
Span3.innerText = "三";
Results.innerText = txtUserInfo;
}
setInterval('DoSearch()', 2000)
</script></head>
<body>
<form id="form1" runat="server">
<div>
姓名:<input id="txtUserName" type="text" value="Janet" />
<br />
<span id="Results" style="background-color: pink; width: 500px;"></span>
<br />
<span id="Span1" style="background-color: pink; width: 500px;"></span>
<br />
<span id="Span2" style="background-color: pink; width: 500px;"></span>
<br />
<span id="Span3" style="background-color: pink; width: 500px;"></span>
</div>
</form>
</body>
</html>
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.Data.SqlClient;public partial class ClientCallbacks : System.Web.UI.Page,ICallbackEventHandler
{
protected string txtUserInfo; //用户基本信息 protected void Page_Load(object sender, EventArgs e)
{
//动态注册JavaScript
String cbReference = Page.ClientScript.GetCallbackEventReference(this, "arg", "ReceiveServerData", "context");
String callbackScript;
callbackScript = "function CallServer(arg, context)" + "{ " + cbReference + "} ;";
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "CallServer", callbackScript, true);
} //引发Callback事件处理
public void RaiseCallbackEvent(string txtFirstName)
{
this.txtUserInfo = "引发Callback事件处理";
if (txtFirstName != null)
{
SqlConnection conn = new SqlConnection("Data Source=.\\sqlexpress;Initial Catalog=Northwind;User ID=sa;Password=zhoushi");
conn.Open(); SqlCommand cmd = new SqlCommand("select EmployeeID,FirstName,City,Address from Employees where FirstName=@FirstName", conn);
cmd.Parameters.Add("@FirstName", SqlDbType.NVarChar, 10).Value = txtFirstName;
SqlDataReader dr = cmd.ExecuteReader(); if (dr.Read())
{
txtUserInfo = "员工代号:" + dr["EmployeeID"] + " ,";
txtUserInfo += "姓名:" + dr["FirstName"] + " ,";
txtUserInfo += "居住城市:" + dr["City"] + " ,";
txtUserInfo += "地址:" + dr["Address"].ToString().Replace("\r\n","") + " ,";
txtUserInfo += "服务器查询时间:" + DateTime.Now.ToLongTimeString();
}
else
{
if (String.IsNullOrEmpty(txtFirstName))
{
txtUserInfo = "请输入姓名";
}
else
{
txtUserInfo = "查无此人!";
}
} cmd.Dispose();
dr.Dispose();
conn.Dispose();
}
} //返回Callback结果
public string GetCallbackResult()
{
return txtUserInfo + "返回员工基本信息"; //返回员工基本信息
}
}
public void RaiseCallbackEvent(string txtFirstName) {....} 不会运行到这个方法.
代码如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ClientCallbacks.aspx.cs" Inherits="ClientCallbacks" %><!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 txtFirstName = document.getElementById("txtUserName");
CallServer(txtFirstName.value, '');
Results.innerText = txtFirstName.value;
Span1.innerText = "1";
Span2.innerText = "2";
Span3.innerText = "3";
} function ReceiveServerData(txtUserInfo)
{
Span3.innerText = "三";
Results.innerText = txtUserInfo;
}
setInterval('DoSearch()', 2000)
</script></head>
<body>
<form id="form1" runat="server">
<div>
姓名:<input id="txtUserName" type="text" value="Janet" />
<br />
<span id="Results" style="background-color: pink; width: 500px;"></span>
<br />
<span id="Span1" style="background-color: pink; width: 500px;"></span>
<br />
<span id="Span2" style="background-color: pink; width: 500px;"></span>
<br />
<span id="Span3" style="background-color: pink; width: 500px;"></span>
</div>
</form>
</body>
</html>
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.Data.SqlClient;public partial class ClientCallbacks : System.Web.UI.Page,ICallbackEventHandler
{
protected string txtUserInfo; //用户基本信息 protected void Page_Load(object sender, EventArgs e)
{
//动态注册JavaScript
String cbReference = Page.ClientScript.GetCallbackEventReference(this, "arg", "ReceiveServerData", "context");
String callbackScript;
callbackScript = "function CallServer(arg, context)" + "{ " + cbReference + "} ;";
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "CallServer", callbackScript, true);
} //引发Callback事件处理
public void RaiseCallbackEvent(string txtFirstName)
{
this.txtUserInfo = "引发Callback事件处理";
if (txtFirstName != null)
{
SqlConnection conn = new SqlConnection("Data Source=.\\sqlexpress;Initial Catalog=Northwind;User ID=sa;Password=zhoushi");
conn.Open(); SqlCommand cmd = new SqlCommand("select EmployeeID,FirstName,City,Address from Employees where FirstName=@FirstName", conn);
cmd.Parameters.Add("@FirstName", SqlDbType.NVarChar, 10).Value = txtFirstName;
SqlDataReader dr = cmd.ExecuteReader(); if (dr.Read())
{
txtUserInfo = "员工代号:" + dr["EmployeeID"] + " ,";
txtUserInfo += "姓名:" + dr["FirstName"] + " ,";
txtUserInfo += "居住城市:" + dr["City"] + " ,";
txtUserInfo += "地址:" + dr["Address"].ToString().Replace("\r\n","") + " ,";
txtUserInfo += "服务器查询时间:" + DateTime.Now.ToLongTimeString();
}
else
{
if (String.IsNullOrEmpty(txtFirstName))
{
txtUserInfo = "请输入姓名";
}
else
{
txtUserInfo = "查无此人!";
}
} cmd.Dispose();
dr.Dispose();
conn.Dispose();
}
} //返回Callback结果
public string GetCallbackResult()
{
return txtUserInfo + "返回员工基本信息"; //返回员工基本信息
}
}
解决方案 »
- SELECT 子句中包含一个保留字、拼写错误或丢失的参数,或标点符号不正确。
- 请文如何在VSS开发中 从数据库读取byte[]流写入文件中
- 序列化对象时候出错!~ 急急急!~~~
- 关于泛型的疑问
- 急的不得了,80分求二级联动效果,dropdownlist绑定数据库实现。最好是ajax,js也行,只要能实现就行。
- 一个简单的问题.正确立刻给分.先给100分如果正确立刻在给100分,通知你来拿!!!!!
- 为什么我的User.IsInRole("student")总是False 在线等(特菜的问题 坚决马上给分)
- 关于刷新父页面?
- 救命呀,急!急!十万火急!求教大侠为何导航条显示成问号了,
- 急问:HttpResponse的方法断续下载文件,是不是不支持下载mht格式的文件呀?
- 除非指定了 UpdateCommand,否则数据源“SqlDataSource2”不支持更新操作。
- ModelPopup触发不了OkControlID对应button的后台事件。急
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.Data.SqlClient;public partial class ClientCallbacks : System.Web.UI.Page,ICallbackEventHandler
{
protected string txtUserInfo; //用户基本信息 protected void Page_Load(object sender, EventArgs e)
{
//动态注册JavaScript
String cbReference = Page.ClientScript.GetCallbackEventReference(this, "arg", "ReceiveServerData", "context");
String callbackScript;
callbackScript = "function CallServer(arg, context)" + "{ " + cbReference + "} ;";
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "CallServer", callbackScript, true);
} //引发Callback事件处理
public void RaiseCallbackEvent(string txtFirstName)
{
this.txtUserInfo = "引发Callback事件处理";
if (txtFirstName != null)
{
SqlConnection conn = new SqlConnection("Data Source=.\\sqlexpress;Initial Catalog=Northwind;User ID=sa;Password=zhoushi");
conn.Open(); SqlCommand cmd = new SqlCommand("select EmployeeID,FirstName,City,Address from Employees where FirstName=@FirstName", conn);
cmd.Parameters.Add("@FirstName", SqlDbType.NVarChar, 10).Value = txtFirstName;
SqlDataReader dr = cmd.ExecuteReader(); if (dr.Read())
{
txtUserInfo = "员工代号:" + dr["EmployeeID"] + " ,";
txtUserInfo += "姓名:" + dr["FirstName"] + " ,";
txtUserInfo += "居住城市:" + dr["City"] + " ,";
txtUserInfo += "地址:" + dr["Address"].ToString().Replace("\r\n","") + " ,";
txtUserInfo += "服务器查询时间:" + DateTime.Now.ToLongTimeString();
}
else
{
if (String.IsNullOrEmpty(txtFirstName))
{
txtUserInfo = "请输入姓名";
}
else
{
txtUserInfo = "查无此人!";
}
} cmd.Dispose();
dr.Dispose();
conn.Dispose();
}
} //返回Callback结果
public string GetCallbackResult()
{
return txtUserInfo + "返回员工基本信息"; //返回员工基本信息
}
}
function CallServer(arg, context) { WebForm_DoCallback('__Page',arg,ReceiveServerData,context,null,false); } //]]>
下面这个没执行: function ReceiveServerData(txtUserInfo)
{
Results.innerText = txtUserInfo;
}
下面两个方法跟踪不了:public void RaiseCallbackEvent(string txtFirstName)
public string GetCallbackResult()
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ClientCallbacks.aspx.cs" Inherits="ClientCallbacks" %><!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 txtFirstName = document.getElementById("txtUserName");
CallServer(txtFirstName.value, '');
Results.innerText = txtFirstName.value;
Span1.innerText = "1";
Span2.innerText = "2";
Span3.innerText = "3";
} function ReceiveServerData(txtUserInfo)
{
Span3.innerText = "三";
Results.innerText = txtUserInfo;
}
setInterval('DoSearch()', 2000)
</script> </head>
<body>
<form id="form1" runat="server">
<div>
姓名: <input id="txtUserName" type="text" value="Janet" />
<br />
<span id="Results" style="background-color: pink; width: 500px;"> </span>
<br />
<span id="Span1" style="background-color: pink; width: 500px;"> </span>
<br />
<span id="Span2" style="background-color: pink; width: 500px;"> </span>
<br />
<span id="Span3" style="background-color: pink; width: 500px;"> </span>
</div>
</form>
</body>
</html> 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;public partial class ClientCallbacks : System.Web.UI.Page, ICallbackEventHandler
{
protected string txtUserInfo; //用户基本信息 protected void Page_Load(object sender, EventArgs e)
{
//动态注册JavaScript
String cbReference = Page.ClientScript.GetCallbackEventReference(this, "arg", "ReceiveServerData", "context");
String callbackScript;
callbackScript = "function CallServer(arg, context)" + "{ " + cbReference + ";}";
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "CallServer", callbackScript, true);
} //引发Callback事件处理
public void RaiseCallbackEvent(string txtFirstName)
{
this.txtUserInfo = "引发Callback事件处理";
} //返回Callback结果
public string GetCallbackResult()
{
return txtUserInfo + "返回员工基本信息"; //返回员工基本信息
} }
运行正常你先改成这样,看能否运行,很可能是你数据库查询的部分出错了
感谢阿非,lebeay.