我写了一段js代码
 <script language="Vbscript" type="text/javascript">
        function test()
        {
            alert("aaa");
        }
    </script>
下面是调用的代码
<body>
    <form id="form1" runat="server">
    <div>
         <asp:Button ID="Button1" runat="server" Text="Button" OnClick ="test()" />
    </div>
    </form>
</body>我编译时总报 错误 1  “test”不是“ASP.abc_aspx”的成员。

解决方案 »

  1.   

    客户端事件使用onClientClick="test()"或者Page_Load里Button1.Attributes.Add("onclick","test()");
      

  2.   

    language="Vbscript" 改成language="javascript" 试试
      

  3.   

    language="javascript"你的語法錯了不是vbs的
      

  4.   

    忘了vbs  彈出框是 msgbox "aaa"
      

  5.   


    使用1楼的方法 可以了,但不知道为什么
    ==
    因为你调用的是客户端事件,应这样写 
            <asp:Button ID="Button1" runat="server" Text="Button" OnClinetClick ="test()" />, Button1.Attributes.Add("onclick","test()");这就是给Button1单击时增加一个test()客户端事件,
    而OnClick 调用的是服务端事件。
      

  6.   


    因为你的源代码中的Onclick="test()" 中的test(),Visual Studio调用的是你的页面文件的后台程序中的事件处理程序。
    比如:你的前台页面是a.aspx,对应的后台页面a.aspx.cs,则Onclick调用的是a.aspx.cs中的test(),而不是a.aspx中的test()。因此如果要调用a.aspx中的test(),必须用OnClientClick属性来设定,或者在a.aspx.cs的Load()中添加Button1.Attributes.Add("onclick","test()");