专家请帮忙~asp.net中调用JavaScript的错误
大家好。我是初学者。我要在asp.net里调用一段JavaScript check_word1()的功能,但是老是出现编译器错误信息: BC30456: “Check_word1”不是“ASP.WebForm1_aspx”的成员。 请帮我看下以下代码要怎么修改。
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm1.aspx.vb" Inherits="spelling.WebForm1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>WebForm1</title>
<script language="JavaScript">
function Check_word1()
var key1, word1;
key1 = "cat";
word1 = TextBox1.text;
var times = 0;
{
var result, correct = false;
while (times<3 && correct == false)
{
result = TextBox1.text;
times++;
if (result == key1)
{
correct = true;
}
else
{
alert("Try again!");
return times;
}
}
if (correct == true)
{
alert("You are great!");
}
else
{
alert("The correct answer is " + key1 + ".");
}
}
</script>
<script language="vb" runat="server">
Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
Response.Write("<script>Check_word1()</script>")
End Sub
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
btnSubmit.Attributes.Add("onclick", "return Check_word1();")
End Sub
</script>
<meta content="True" name="vs_snapToGrid">
<meta content="True" name="vs_showGrid">
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<TABLE id="Table1" style="Z-INDEX: 101; LEFT: 104px; WIDTH: 451px; POSITION: absolute; TOP: 56px; HEIGHT: 248px"
cellSpacing="1" cellPadding="1" width="451" align="center" border="1">
<TR>
<TD align="center"><asp:label id="Label1" runat="server" Height="24px" Width="32px">猫</asp:label></TD>
<TD align="center"><asp:textbox id="TextBox1" runat="server" Width="144px"></asp:textbox></TD>
<TD align="center"><asp:button id="btnSubmit" onclick="Check_word1()" runat="server" Height="24px" Width="56px"
Text="Check"></asp:button></TD>
</TR>
</TABLE>
</form>
</body>
</HTML>
--------------------编程问答-------------------- 你要把它RegisterStartUpScript写到客户端才可。
调用write写的时候会写到页的顶部 --------------------编程问答-------------------- 楼主似乎发了俩个帖子,
楼主可以先用vb代码进行直接验证,直接写button的click事件中做,
另 我在另一个帖子中已经说了俩点~
补充:.NET技术 , ASP.NET