【发布时间】:2014-03-17 17:19:37
【问题描述】:
我试图在单击按钮(服务器控件)时调用 javascript 函数。当我为上述目的使用 html 按钮控件(带有runat="server" 属性)时,我能够做到,
但是当我使用 ASP.net 按钮控件(web 控件)时,它给了我
错误:BC30456:“myFunction”不是“ASP.webform1_aspx”的成员。
有什么区别?
对于案例 1 我的代码使用 html 按钮控件,案例 2 是我使用 ASP.net Web 控件的代码:
案例 1:
<html>
<head>
<script >
function myFunction()
{
alert("Hello World!");
}
</script>
</head>
<body>
<button runat="server" onclick="myFunction()">Try it</button>
</body>
</html>
**案例2:**
<html>
<head>
<script >
function myFunction()
{
alert("Hello World!");
}
</script>
</head>
<body>
<asp:Button id="Button" onclick="myFunction()" runat="server" Text="Button" />
</body>
</html>
【问题讨论】:
-
您的 asp:button 丢失 "
-
@Zaki,这是一个错字,我实际使用过:
标签: javascript html asp.net