日期:2014-05-17  浏览次数:20752 次

为什么想要在Javascript中插入ASP的代码无法执行呢?
这里我用到两个页面,第一个是用来显示学生信息的,包括学号、姓名、班级、课程号、成绩,然后显示出来以后在每条记录最右边动态生成两个按钮,一个是修改,一个是删除。目前删除已经没问题,问题就在修改。

在修改的页面,我首先抓取"iStuDisplay.asp"这个页面中数据库里的数据,将“学号、姓名等”信息先显示出来,然后下面有一个Text框,一个Button按钮,Text框输入需要修改的分数,Button提交。

问题就出现在这里,我的设想是输入框中输入完数据后,本页面再次抓取Text框中的内容,然后用ASP来处理,处理完了用"Response.Redirect"跳转到"iStuDisplay.asp"显示修改完的内容。我把这段数据库操作的ASP代码插入在window.confirm()中,点击“是”就执行,“否”就不执行。但是发现无法执行,这是为什么呢?难道需要其它方法来控制数据库操作的执行?

报错的信息是”发生了未处理的异常(“关键字'WHERE'附近有语法错误。”),发生位置是w3wp.exe[4676]。我不觉得SQL语句有什么问题啊

如果在JS中判断是否执行这段ASP代码,怎么改比较好呢?

代码如下:

HTML code
<%
    Dim getSelectedIndex
    Dim getSNO, getSCLASS, getSNAME, getCNO, getGRADE

    '//从“iStuDisplay.asp”获取:学号、班级、课程号、成绩
    getSelectedIndex = Request("selectedIndex")

    getSNO = Request("txtSNO" &getSelectedIndex)
    getSNAME = Request("txtSName" &getSelectedIndex)
    getSCLASS = Request("txtSCLASS" &getSelectedIndex)
    getCNO = Request("txtCNO" &getSelectedIndex)
    getGRADE = Request("txtGRADE" &getSelectedIndex)
%>

<!--打印从“iStuDisplay.asp”获取的“学号、班级、课程号、成绩”信息-->
<b><font size = "2" color = "Maroon">您所需要修改的记录如下:</font></b><br>
    <table width="40%" border="1" bordercolor="DarkSlateGray" cellspacing="1" cellpadding="3">
        <tr bgcolor=DarkBlue >
            <th><font size='2' color="White">学号</font></th>
            <th><font size='2' color="White">姓名</font></th>
            <th><font size='2' color="White">班级</font></th>
            <th><font size='2' color="White">课程号</font></th>
            <th><font size='2' color="White">成绩</font></th>
        </tr>
<%
    Response.Write("<tr bgcolor = white>")
    Response.Write("<td><font size='2'>"&getSNO&"</font></td>")
    Response.Write("<td><font size='2'>"&getSCLASS&"</font></td>")
    Response.Write("<td><font size='2'>"&getSNAME&"</font></td>")
    Response.Write("<td><font size='2'>"&getCNO&"</font></td>")
    Response.Write("<td><font size='2'>"&getGRADE&"</font></td>")
    Response.Write("</tr>")
%>
    </table>
    
<html>
<body>
<body style="background-color:DarkSeaGreen;">

<form name = "updateForm">
<font size = "2">修改为:<input type = "text" name = "txtUpdateScore" size ="4" maxlength = "3"> 分 <input type = "Button" name = "btnUpdateScore" value = "点击修改" onclick = "btnUpdateScoreCheck()">
</form></font>

<script language = "Javascript">

    function btnUpdateScoreCheck()
    {
        if (window.confirm("是否确定修改?") == true )
        {
            //如果选择“是”则执行修改操作
            document.updateForm.action = "iStuUpdating.asp";
            document.updateForm.target = "_self";
            document.updateForm.method = "post";
            document.updateForm.submit();
                
            //执行以后这段代码就不见了,报错了!
            <%    
                '//从“iStuUpdating.asp”(即本页面)获取输入的需要修改的分数值
                Dim getTxtUpdateScore
                getTxtUpdateScore = Request("txtUpdateScore")