On an old site I've just been given to modify, I added some VBScript (not familiar with it, just trying to fake it until I make it) like so:
'determine whether this unit is a new business
currentYear = Year(Now)
SQLString = "Select NewBiz from MasterUnitsprojSales where CYear = " & currentYear & " and Unit = '" & Unit & "'"
adoRS.Open(SQLString, adoCon)
IsNewBusiness = TRUE 'default (if record not found)
If Not adoRS.EOF Then
IsNewBusiness = adoRS.Fields.Item(0).Value <> 0
End If
adoRS.Close()
ReturnMsg = "Made it to IsNewBusiness logic"
Response.Write("<script type=""text/javascript"">" & vbCrLf)
Response.Write("<!--" & vbCrLf)
Response.Write("alert ('" & ReturnMsg & "');" & vbCrLf)
Response.Write("-->" & vbCrLf)
Response.Write("</script>" & vbCrLf)
Before I added the "End If" line it failed - navigating to that page gave me an err msg.
After adding the "End If" the err msg has gone away, but the javascript alert (which is just there temporarily to let me know that the code really did run) is not displaying, Why not?
Using F12 (I have to run this in IE11, in Compatibility Mode), I looked for this file so that I could put a breakpoint in it, but it did not seem to make itself available.
Based on Archer's answer, I replaced my code with the following:
ReturnMsg = "IsNewBusiness logic not reached"
currentYear = Year(Now)
SQLString = "Select NewBiz from MasterUnitsprojSales where CYear = " & currentYear & " and Unit = '" & Unit & "'"
adoRS.Open(SQLString, adoCon)
IsNewBusiness = TRUE 'default (if record not found)
If Not adoRS.EOF Then
IsNewBusiness = adoRS.Fields.Item(0).Value <> 0
ReturnMsg = "Made it to IsNewBusiness logic"
End If
adoRS.Close()
%> <!-- this indicates the end of aspx - start of markup -->
<script type="text/javascript">
alert("<%= ReturnMsg %>");
</script>
<%
...but I still see no alert when I navigate to the page.
Okay, first things first. You don't need to use Response.Write()
within an aspx file, as that is what will be sent to the browser as markup, after it has been executed. You can put plain markup of any type in there, including Javascript. So, you can change what you currently have to this...
'determine whether this unit is a new business
currentYear = Year(Now)
SQLString = "Select NewBiz from MasterUnitsprojSales where CYear = " & currentYear & " and Unit = '" & Unit & "'"
adoRS.Open(SQLString, adoCon)
IsNewBusiness = TRUE 'default (if record not found)
If Not adoRS.EOF Then
IsNewBusiness = adoRS.Fields.Item(0).Value <> 0
End If
adoRS.Close()
ReturnMsg = "Made it to IsNewBusiness logic"
%> <!-- this indicates the end of aspx - start of markup -->
<script type="text/javascript">
alert("<%= ReturnMsg %>");
</script>
<% <!-- this indicates end of markup but is only required if you have any further aspx code -->