日期:2014-05-18 浏览次数:20551 次
function Abc() { var thestr=document.getElementById('div1').InnerText; var lab=document.getElementById(label1); lab.innerText=thestr; //如果是button lab.value=thethr }
------解决方案--------------------
演示异步回调方法实现,调试通过,纯做演示
<%@ Page Language="C#" %> <!--要实现异步回调接口--> <%@ Implements Interface="System.Web.UI.ICallbackEventHandler" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> // 处理以控件为目标的回调事件 public void RaiseCallbackEvent(String eventArgument) { //调用public void button(string str),eventArgument就是传过来的div.innerText button(eventArgument); } // 返回以控件为目标的回调事件的结果 public string GetCallbackResult() { //返回给客户端的数据(arg),这里不用返回,只是演回调用public void button(string str) return string.Empty; } //你要传的button函数 public void button(string str) { this.Label1.Text = str; } protected void Page_Load(object sender, EventArgs e) { ClientScriptManager cs = Page.ClientScript; //这是注册接收后台事件结果的客户端脚本 String cbReference1 = cs.GetCallbackEventReference(this, "arg", "ReceiveServerData",""); //动态注册 String callbackScript1 = "function Abc(arg, context) {" + cbReference1 + "; }"; cs.RegisterClientScriptBlock(this.GetType(), "Abc",callbackScript1, true); } </script> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>无标题页</title> <script type="text/javascript"> //接收后台事件结果的客户端脚本 function ReceiveServerData(arg, context) { } </script> </head> <body> <form id="form1" runat="server"> <div> <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> <!--input button点击--> <input id="Button1" type="button" value="button" onclick="Abc(document.getElementById('div1').innerText,'')" /> </div> </form> <div id="div1">xxxxxxxx</div> </body> </html>