标签:
实现客户端,服务端异步通信的。
从客户端到服务端的通信:PerformCallback()。PerformCallback就是从客户端到服务端的桥梁,它是单向的只能从客户端发起到服务端。在Perform Callback()括号当中我们可以传递一些参数到服务器端,从而达到更新效果。服务器端的接受并异步刷新:Callback()。当从服务端PerformCallback唤醒以后,响应的控件Callback事件开始执行(控件的服务器事件中可以找到)。
并且通过Parameter键值来获取从客户端传过来的值进行相关的处理。 客户端:Code
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>PerTest</title>
<script language="javascript" type="text/javascript">
//客户端处理下拉框选择项改变事件,client端aspxcombox下拉框改变事件为SelectedIndexChanged
function OnEmployeesChanged(s){
//PerformCallback事件实际上时dev系列控件客户端服务器端异步通信的"大使",通过PerfromCallback事件
//将客户端的通信要求传递给服务端,在服务端通过控件的callback事件来接受相关参数并进行页面异步刷新
devcbxChi.PerformCallback(s.GetValue());
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<dxe:ASPxComboBox runat="server" ID="devcbxPar2" DropDownStyle="DropDownList" EnableIncrementalFiltering="True"
EnableSynchronization="False" ClientInstanceName="devcbxPar2"
Width="160px">
<ClientSideEvents SelectedIndexChanged="function(s, e) { OnEmployeesChanged(s); }"></ClientSideEvents>
</dxe:ASPxComboBox>
<dxe:ASPxComboBox runat="server" ID="devcbxChi" DropDownStyle="DropDownList" EnableIncrementalFiltering="True"
EnableSynchronization="False" ClientInstanceName="devcbxChi"
Width="160px" oncallback="devcbxChi_Callback">
</dxe:ASPxComboBox>
</div>
</form>
</body>
</html>
using DevExpress.Web.ASPxEditors;
Code
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["northwind"].ConnectionString);
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
devcbxPar2.Items.Clear();
string selectSQL = "select EmployeeID,FirstName from Employees";
SqlDataAdapter SDA = new SqlDataAdapter(selectSQL, conn);
DataSet DS = new DataSet();
SDA.Fill(DS);
for (int i = 0; i < DS.Tables[0].Rows.Count; i++)
{
devcbxPar2.Items.Add(new ListEditItem(DS.Tables[0].Rows[i]["FirstName"].ToString().Trim(), DS.Tables[0].Rows[i]["EmployeeID"] .ToString().Trim()));
}
}
} protected void devcbxChi_Callback(object source, DevExpress.Web.ASPxClasses.CallbackEventArgsBase e)
{
//得到从客户端传递过来的参数来进行异步通信响应
string parm = e.Parameter.Trim();
string selectSQL = "select TerritoryID from EmployeeTerritories where EmployeeID=‘" + parm + "‘";
SqlDataAdapter SDA = new SqlDataAdapter(selectSQL, conn);
DataSet DS = new DataSet();
SDA.Fill(DS);
devcbxChi.Items.Clear();
for (int i = 0; i < DS.Tables[0].Rows.Count; i++)
{
devcbxChi.Items.Add(DS.Tables[0].Rows[i]["TerritoryID"].ToString().Trim());
}
devcbxChi.SelectedIndex = 0; }
原文地址:http://blog.csdn.net/xueer8835/article/details/6018969
标签:
原文地址:http://www.cnblogs.com/haizine/p/5762302.html