【转】如何在客户端触发服务器端事件并获取客户端传递的参数

原文链接:http://www.cnblogs.com/codefan/archive/2006/05/29/411770.html

在.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

在.cs页面中

 1private 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}

1private void LinkButton1_Click(object sender, System.EventArgs e)
2{
3    Response.Write(requestArgument[0]);
4    Response.Write(requestArgument[1]);
5}

posted on 2008-07-10 16:39  王丹小筑  阅读(184)  评论(0)    收藏  举报

导航