前台代码:
1
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
2
3
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
4
<html xmlns="http://www.w3.org/1999/xhtml">
5
<head runat="server">
6
<title>ICallbackEventHandler的一个例子</title>
7
</head>
8
<body>
9
<form id="form1" runat="server">
10
<div>
11
<asp:DropDownList ID="ddlSelect" runat="server">
12
<asp:ListItem Text="1" Value="选择的是1">1</asp:ListItem>
13
<asp:ListItem Text="2" Value="选择的是2">2</asp:ListItem>
14
<asp:ListItem Text="3" Value="选择的是3">3</asp:ListItem>
15
<asp:ListItem Text="4" Value="选择的是4">4</asp:ListItem>
16
<asp:ListItem Text="5" Value="选择的是5">5</asp:ListItem>
17
</asp:DropDownList>
18
<br />
19
<asp:TextBox ID="txtword" runat="server"></asp:TextBox><br />
20
<asp:Label ID="lblword" runat="server" Text="Label"></asp:Label>
21
</div>
22
23
<script type="text/javascript">
24
25
function SetSuppInfo()
26
{
27
var SuppID = document.getElementById('<%=ddlSelect.ClientID %>').value;
28
CSGetSuppInfo(SuppID);
29
}
30
31
function CSGetSuppInfo(SuppID)
32
{
33
args = "GetFunction^" + SuppID;
34
<%= Page.ClientScript.GetCallbackEventReference(this,"args","GetSuppInfoReturn","") %>
35
}
36
37
function GetSuppInfoReturn(result)
38
{
39
if(result != "")
40
{
41
var EmpName = document.getElementById('<%=txtword.ClientID %>');
42
EmpName.value = result;
43
var EmpTel = document.getElementById('<%=lblword.ClientID %>');
44
EmpTel.innerText = result;
45
}
46
else
47
{
48
alert("没有返回值!");
49
}
50
51
}
52
</script>
53
54
</form>
55
</body>
56
</html>
后台代码:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>2

3
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">4
<html xmlns="http://www.w3.org/1999/xhtml">5
<head runat="server">6
<title>ICallbackEventHandler的一个例子</title>7
</head>8
<body>9
<form id="form1" runat="server">10
<div>11
<asp:DropDownList ID="ddlSelect" runat="server">12
<asp:ListItem Text="1" Value="选择的是1">1</asp:ListItem>13
<asp:ListItem Text="2" Value="选择的是2">2</asp:ListItem>14
<asp:ListItem Text="3" Value="选择的是3">3</asp:ListItem>15
<asp:ListItem Text="4" Value="选择的是4">4</asp:ListItem>16
<asp:ListItem Text="5" Value="选择的是5">5</asp:ListItem>17
</asp:DropDownList>18
<br />19
<asp:TextBox ID="txtword" runat="server"></asp:TextBox><br />20
<asp:Label ID="lblword" runat="server" Text="Label"></asp:Label>21
</div>22

23
<script type="text/javascript">24
25
function SetSuppInfo()26
{27
var SuppID = document.getElementById('<%=ddlSelect.ClientID %>').value;28
CSGetSuppInfo(SuppID);29
}30
31
function CSGetSuppInfo(SuppID)32
{33
args = "GetFunction^" + SuppID;34
<%= Page.ClientScript.GetCallbackEventReference(this,"args","GetSuppInfoReturn","") %>35
}36
37
function GetSuppInfoReturn(result)38
{39
if(result != "")40
{41
var EmpName = document.getElementById('<%=txtword.ClientID %>');42
EmpName.value = result;43
var EmpTel = document.getElementById('<%=lblword.ClientID %>');44
EmpTel.innerText = result;45
}46
else47
{48
alert("没有返回值!");49
}50
51
}52
</script>53

54
</form>55
</body>56
</html> 1
using System;
2
using System.Data;
3
using System.Configuration;
4
using System.Web;
5
using System.Web.Security;
6
using System.Web.UI;
7
using System.Web.UI.WebControls;
8
using System.Web.UI.WebControls.WebParts;
9
using System.Web.UI.HtmlControls;
10
11
public partial class _Default : System.Web.UI.Page, ICallbackEventHandler
12
{
13
protected void Page_Load(object sender, EventArgs e)
14
{
15
ddlSelect.Attributes.Add("onchange", "SetSuppInfo();return false;");
16
}
17
18
public string GetFunction(string str)
19
{
20
if (str == "")
21
{
22
return "";
23
}
24
else
25
{
26
return str;
27
}
28
}
29
ICallbackEventHandler Members
53
}
54
using System;2
using System.Data;3
using System.Configuration;4
using System.Web;5
using System.Web.Security;6
using System.Web.UI;7
using System.Web.UI.WebControls;8
using System.Web.UI.WebControls.WebParts;9
using System.Web.UI.HtmlControls;10

11
public partial class _Default : System.Web.UI.Page, ICallbackEventHandler12
{13
protected void Page_Load(object sender, EventArgs e)14
{15
ddlSelect.Attributes.Add("onchange", "SetSuppInfo();return false;");16
}17

18
public string GetFunction(string str)19
{20
if (str == "")21
{22
return "";23
}24
else25
{26
return str;27
}28
}29
ICallbackEventHandler Members53
}54



浙公网安备 33010602011771号