传统的ASP验证服务器结果 [英] classic asp verify the server result

查看:354
本文介绍了传统的ASP验证服务器结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想检查或取消选中的复选框取决于来自服务器的数据结果。但是,在我做错了,我不能低于code正确使用?

 <%
昏暗after_save的,IN_VIEW,Y
暗淡的SQL,数据
SQL =SELECT code,名称,值FROM MYTABLE其中code ='&放大器;用户和放大器; '
数据=数据(SQL)
%GT;
    <%如果IsArray的(数据)然后%GT;
         &所述;%如果((数据(1,0)=after_save的)和(数据(2,0)=Y))然后%GT;
                。的document.getElementById(chkSave)检查==真;
         <%结束如果%GT;
         &所述;%如果((数据(1,0)=IN_VIEW)和(数据(2,0)=Y))然后%GT;
                。的document.getElementById(chkVIEW)检查==真;
         <%结束如果%GT;
  <%结束如果%GT;


解决方案

您正在尝试服务器端code。与客户端code以一种非常奇怪的方式结合起来。有时候,有必要做(即使用服务器端的VBScript编写客户端Javascript),但如果我理解正确你的意图,这不是在这里需要的。

基本上,如果这其实是一个传统的ASP页面,然后某处页面上,你会产生问题的复选框。因此,所有你需要做的就是把你的数据库调用某个地方在这之前,然后当你生成的复选框,可以输出检查='检查',还是不行,这取决于

<子>请注意,我不知道是什么数据=数据(SQL)的解释是:。有没有办法为它是有效的VBScript code - 括号里的数组,但字符串不是一个有效的数组索引,然后将其分配到自己喜欢吗?无论如何,我忽略的部分。

&LT; HTML和GT;
&LT; HEAD&GT;
&LT;%
暗淡after_save的,IN_VIEW
昏暗的SQL,RS,康涅狄格州
昏暗的用户
......等等等等等等,给出一个值用户,设置您的数据库连接,等等等等....SQL =SELECT code,名称,[值] FROM MYTABLE其中code ='&放大器;用户和放大器; '
- (价值是SQL中保留关键字,因此括号中)
集RS =的Server.CreateObject(ADODB.Recordset)
RS.Open SQL中,康涅狄格州,1,2' - 这是相当handwavy和不可能实际
- 工作原样;使用你有意义的选项和连接方法
做,直到RS.EOF
     - 我不知道你的数据是如何设置的;这可能毫无意义。
    ' - 这个想法是,从数据库中读取的复选框状态,
     - 供日后参考变量,他们坚持。
    选择案例RS(名称)
        案after_save的after_save的= RS(值)
        案IN_VIEWIN_VIEW = RS(值)
    结束选择
    RS.Movenext
循环
RS.Close
集RS =什么
%GT;
&LT; /头&GT;
&LT;身体GT;
&LT;形式方法=邮报行动=myformhandler.asp&GT;
&LT;! - 表单字段和东西 - &GT;
&LT;输入类型=复选框NAME =chkSaveID =chkSave&LT;%
如果after_save的=Y然后的Response.Write检查='检查'
%GT;值=Y&GT;&LT;标签=chkSave&GT;保存后&LT; /标签&gt;
&LT;输入类型=复选框NAME =chkViewID =chkView&LT;%
如果IN_VIEW =Y然后的Response.Write检查='检查'
%GT;值=Y&GT;&LT;标签=chkView&gt;在查看&LT; /标签&gt;
&LT;! - 多形式的东西 - &GT;
&LT; /表及GT;
&LT; /身体GT;
&LT; / HTML&GT;

I am trying to check or unchecked the check-boxes depends upon the data results that comes from server. But I cannot use below code correctly where I am doing wrong?

<%
Dim AFTER_SAVE, IN_VIEW, Y
Dim SQL, Data
SQL = " SELECT code, name, value FROM mytable WHERE code = '" & User & "'" 
Data = Data(SQL)
%>  
    <%If IsArray(Data) Then%>
         <%If ((Data(1,0) = "AFTER_SAVE") AND (Data(2,0) = "Y")) Then %>      
                document.getElementById("chkSave").checked == true;                      
         <%End If%>
         <% If ((Data(1,0) = "IN_VIEW") AND (Data(2,0) = "Y")) Then %>       
                document.getElementById("chkVIEW").checked == true;  
         <%End If%>
  <%End If%>

解决方案

You're trying to combine server-side code with client-side code in a very strange way. Sometimes, it's necessary to do that (i.e. use server-side VBScript to write client-side Javascript), but if I'm understanding your intent correctly, it's not needed here.

Basically, if this is actually a classic ASP page, then somewhere on that page you're generating the checkboxes in question. So all you need to do is put your database call somewhere before that, and then when you generate the checkboxes, you can output a checked='checked', or not, depending.

Note that I have no clue what Data = Data(SQL) is supposed to mean. There's no way for it to be valid VBScript code - parentheses are for arrays, but a string is not a valid array index, and then to assign it to itself like that? Anyway, I'm ignoring that part.

<html>
<head>
<%
Dim AFTER_SAVE, IN_VIEW
Dim SQL, RS, Conn
Dim User
'...blah blah blah, give a value to User, set up your DB connection, etc. etc....

SQL = "SELECT code, name, [value] FROM mytable WHERE code = '" & User & "'"
'- ("value" is a reserved keyword in SQL, hence the brackets)
Set RS = Server.Createobject("ADODB.Recordset")
RS.Open SQL, Conn, 1, 2 '- this is rather handwavy and unlikely to actually
'- work as-is; use the options and connection methods that make sense for you
Do Until RS.EOF
    '- I have no idea how your data is set up; this may make no sense.
    '- The idea is, read the checkbox states from your database, and 
    '- stick them in variables for later reference.
    Select Case RS("name")
        Case "AFTER_SAVE" AFTER_SAVE = RS("value")
        Case "IN_VIEW"   IN_VIEW = RS("value")
    End Select
    RS.Movenext
Loop
RS.Close
Set RS = Nothing
%>
</head>
<body>
<form method="post" action="myformhandler.asp">
<!-- form fields and stuff -->
<input type="checkbox" name="chkSave" id="chkSave" <%
If AFTER_SAVE = "Y" Then Response.Write "checked='checked'"
%> value="Y"><label for="chkSave">After save</label>
<input type="checkbox" name="chkView" id="chkView" <%
If IN_VIEW = "Y" Then Response.Write "checked='checked'"
%> value="Y"><label for="chkView">In view</label>
<!-- more form stuff -->
</form>
</body>
</html>

这篇关于传统的ASP验证服务器结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆