Page 1 of 1

VBscript ASP Help If Then

Posted: Mon Aug 27, 2012 3:42 am
by rcandela
I'm trying to make this button appear only if a value in SQL = 'Deactive'

For some reason, the way my If Then is set up, doesn't make the button () appear when the statement is in fact true.

Code: Select all

<% IF ((rsUsersMod.Fields.Item("STATUS") = "Deactive")) Then%> 
    <form action="" method="POST" name="reactivateuser" > 
        <input name="deleteButton" type="image" src="images/reactivate.png" value="Reactivate" onclick="return confirm('Are you sure you want to reactivate this user?');"> 
        <input type="hidden" name="delete" value="reactivate"> 
        <input type="hidden" name="recordId" value="<%= rsUsersMod.Fields.Item("UNIQUE_ID").Value %>"> 
    </form>
<%End If%> 

VBscript ASP Help If Then

Posted: Mon Aug 27, 2012 7:17 am
by rcandela
All that does is actually display the Field Value on the page, but it doesn't make the form appear afterwards:

Code: Select all

<% 
value=rsUsersMod.Fields("STATUS").Value 
Response.Write(value) 
IF value = "Deactive" Then 
 %> 
    <form action="" method="POST" name="reactivateuser" > 
        <input name="deleteButton" type="image" src="images/reactivate.png" value="Reactivate" onclick="return confirm('Are you sure you want to reactivate this user?');"> 
        <input type="hidden" name="delete" value="reactivate"> 
        <input type="hidden" name="recordId" value="<%= rsUsersMod.Fields.Item("UNIQUE_ID").Value %>"> 
    </form>
<%End If%>

VBscript ASP Help If Then

Posted: Mon Aug 27, 2012 7:53 am
by jvierra
I am surptised that I can still write proficiently in ASP> It ha been a long time. AASP.NET is so much easier.

Here is a complete and working example:

Code: Select all

<%@ language="VBSCRIPT" %>
<%
 Dim rs
 Set conn = Server.CreateObject("ADODB.Connection")
 conn.ConnectionString="Provider=SQLNCLI10.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=WebTestDB;Data Source=.sqlexpress;"
 conn.Open
 Set rs = conn.Execute("select * from dbo.Names")
%>
<html>
<head>
<meta name="GENERATOR" content="SAPIEN Technologies PrimalScript 2012">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Document Title</title>
</head>
<body>
<table>
<%While Not rs.EOF%>
    <%If LCase(Trim(rs.Fields("FirstName").Value)) <> "joe" Then%>
 <tr>
  <td><%=rs.Fields("ID").Value%></td>
  <td><%=rs.Fields("FirstName").Value%></td>
  <td><%=rs.Fields("LastName").Value%></td>
 </tr>
 <%End If%>
<%rs.MoveNext%>
<%Wend%>
 
</table>
</body>
</html>

I have no idea what is in your database. Y have to attend to teh fact that matches against data require very special handling for many reasons.

A database can have unicode characters. It can have spaces after or before the field contents. In most cases it is important to force the case and trim the strings. If the database character set is wrong then you may not be able to use ASP.

I cannot see your database and I cannot gues as to what you are doing. You must addess these issues on your own. I have shown you the mechanism for assuring the logic will work. I have no idea if you are typing it in correctly or if the values in your database are correct.