【转】如何在客户端触发服务器端事件并获取客户端传递的参数
原文链接:http://www.cnblogs.com/codefan/archive/2006/05/29/411770.html
在.cs页面中
在.aspx页面中
1
<html>
2
<head>
3
<script language = "javascript">
4
function onClick()
5
{
6
var rowno =1; //行号
7
var val = 1; //对应行的值
8
__doPostBack('lnkButton',rowno + '|' + val);
9
}
10
</script>
11
</head>
12
<body>
13
<form id = "frm" runat = "server" method = "post">
14
<asp:Button id = "btnOK" runat = "server" text = "触发服务器端事件" onclick = "onClick();"></asp:Button>
15
<asp:linkbutton id = "lnkButton" runat = "server"></asp:linkbutton>
16
</form>
17
</body>
18
<html>2
<head>3
<script language = "javascript">4
function onClick()5
{6
var rowno =1; //行号7
var val = 1; //对应行的值8
__doPostBack('lnkButton',rowno + '|' + val);9
}10
</script>11
</head>12
<body>13
<form id = "frm" runat = "server" method = "post">14
<asp:Button id = "btnOK" runat = "server" text = "触发服务器端事件" onclick = "onClick();"></asp:Button>15
<asp:linkbutton id = "lnkButton" runat = "server"></asp:linkbutton>16
</form>17
</body>18

在.cs页面中
1
private string[] requestArgument
2
{
3
get
4
{
5
if (Request.Form["__EVENTARGUMENT"] != null)
6
{
7
return Request.Form["__EVNETARGUMENT"].ToString().Split(new char[]{'|'});
8
}
9
return null;
10
}
11
12
}
private string[] requestArgument2
{3
get4
{5
if (Request.Form["__EVENTARGUMENT"] != null)6
{7
return Request.Form["__EVNETARGUMENT"].ToString().Split(new char[]{'|'});8
}9
return null;10
}11

12
}1
private void LinkButton1_Click(object sender, System.EventArgs e)
2
{
3
Response.Write(requestArgument[0]);
4
Response.Write(requestArgument[1]);
5
}
private void LinkButton1_Click(object sender, System.EventArgs e)2
{3
Response.Write(requestArgument[0]);4
Response.Write(requestArgument[1]);5
}本贴子以“现状”提供且没有任何担保,同时也没有授予任何权利
This posting is provided "AS IS" with no warranties, and confers no rights.
This posting is provided "AS IS" with no warranties, and confers no rights.

浙公网安备 33010602011771号