可以用以下变通的方法实现用JavaScript调用服务器端的事件方法 2 1、增加如下JavaScript方法 3 这个就是将Asp.Net 中生成的脚本Copy过来,嘿嘿,很贼哦。 4 function __doPostBack(eventTarget, eventArgument) 5 { 6 var theform; 7 if (window.navigator.appName.toLowerCase().indexOf("microsoft") > -1) 8 { 9 theform = document.Form1; 10 } 11 else 12 { 13 theform = document.forms["Form1"]; 14 } 15 theform.__EVENTTARGET.value = eventTarget.split("$").join(":"); 16 theform.__EVENTARGUMENT.value = eventArgument; 17 theform.submit(); 18 } 19 20 //以下就是要从JavaScript中通知服务器端,你该干活了 21 function NotifyServer() 22 { 23 //.可以做一些设置,判断 24 25 Button1是服务器控件的ID,'abc' 可以自己设置,这个我需要给服务器传递一些消息数据,平时直接用'即可 26 __doPostBack('Button1','abc') 27 } 28 29 2、aspx 页面 30 要增加 以下两个隐藏字段 31 <input type="hidden" name="__EVENTTARGET"> 32 <input type="hidden" name="__EVENTARGUMENT"> 33 34 <asp:Button id="Button1" runat="server" Text="Button" Visible="False"></asp:Button> 35 36 这里就是要执行Button1 的后台代码,同时要将他的Visible 设置成 False ,(虽然资料说 不能将Enable 设置成False,但是我试了一下 将Enabled设置成False还是可以用的 37 38 同时增加一个 39 <input type="button" id="but" onclick="NotifyServer()" value="ServerExecute"> ,执行服务器代码 40 41 3、aspx.vb 页面代码 42 Response.Write("alert('" & Request("__EVENTARGUMENT").ToString() & "'"); ") 43 这里的Request("__EVENTARGUMENT").ToString() 就是'abc'的内容 44 45 4、注意事项 46 用此种方法,页面中不能有AutoPost=True 的服务器控件,因为有AutoPost=True的控件的页面系统会自动生成以上的代码(2个hidden控件,还有一个__doPostBack函数),如果你的页面中 有AutoPost=True的服务器控件,那么你不需要加以上的代码(2个hidden控件,还有一个__doPostBack函数),直接用__doPostBack函数吧