ASP conditional error - asp-classic

i am trying to use an ASP conditional here:
if (Request.Cookies("username")) and
(Request.Cookies("password")) <> ""
Then
And i keep getting this error:
Type mismatch: '[string: ""]'
Any ideas what I am getting that?

try
if (Request.Cookies("username") <> "") and (Request.Cookies("password") <> "") Then

Actually, I would do the following..
if (!string.IsNullOrEmpty(Request.Cookies("username")) &&
!string.IsNullOrEmpty(Request.Cookies("password")))
{
// Do your stuff, here :)
}
Get into the habit of using string.IsNullOrEmpty for testing variables and string.Empty for setting values, if u don't want a string to be null.

Related

XQuery Invalid entity reference error caused by "&" entity reference

I'm trying to run this line xdmp:unquote(concat('<info>', string( $paragraph) , '</info>')) but I've got the following error: xdmp:unquote("<info>LEARNING & MEMORY</info>") -- Invalid entity reference " " at line 1. It seems like this entity reference & is causing the problem. I tried to remove it using replace function but it still present. What should I do?
I am assuming that you have something like this-
let $paragraph := <p>LEARNING & MEMORY</p>
return
xdmp:unquote(fn:concat('<info>', fn:string($paragraph),'</info>'))
And that the result you want is XML that looks like-
<info>LEARNING & MEMORY</info>
The ampersand is definitely the issue and the workaround is to use the "repair-full" option. This example works:
let $paragraph := <p>LEARNING & MEMORY</p>
let $contents := xdmp:unquote($paragraph, "", "repair-full")
return
<info>{$contents}</info>

Cannot implicitly convert type "string" to "bool" when using if condition?

When I write if condition in one line for the textbox i.e.
if (txtNotes.Text.Equals(" ") ? string.Empty: gvrow.Cells[6].Text)
I am getting the error stating:
Cannot implicitly convert type "string" to "bool"
Just want to check where I am going wrong.
You're confusing the standard if statement syntax with the ternary operator ?:. It's either:
txtNotes.Text = txtNotes.Text.Equals(" ") ? string.Empty : gvrow.Cells[6].Text;
or
if (txtNotes.Text.Equals(" "))
{
txtNotes.Text = string.Empty;
}
else
{
txtNotes.Text = gvrow[6].Cells.Text;
}
Edit: from your comment you've stated your setting the value of txtNotes.Text, so I recommend using the ternary operator to achieve this.

converting code into classic asp

I want to convert the below string into classic asp code can any one help
email has some value but it is not going inside the Loop
Can any one help me.
If (IsEmpty(email) And IsNull(email)) Then
EndIf
The code looks like its VBScript already so there is no "conversion" needed, however the code is faulty. Should be:
If IsEmpty(email) Or IsNull(email) Then
End If
a variable cannot both be empty and contain a Null at the same time hence the orginal conditional expression was always false.
You could always try:
If IsEmpty(email) = True Then
'uninitialized
ElseIf IsNull(email) = True Then
'contains null value
ElseIf email = ""
'contains zero length string
Else
'Response.Write email
'MsgBox email
End If
In most cases I try to code so that the variable is guaranteed to be initialized so you don't need to run the IsEmpty check.
Option Explicit
Dim email
email = ""
Why don't you just check the length of the email variable:
If Len(Trim(email)) > 0 Then
Else
YOUR CODE HERE
End If

Problems with If Statement (ASP.NET)

Dim custEmail As String
Dim inputEmail As String
custEmail = dt.Rows(0).Item("email")
inputEmail = email_add.Text
if (custEmail.toString() == inputEmail.toString() ){
label1.Text = custEmail
}
End If
This code is giving an error: Compiler Error Message: BC30201: Expression expected.
I just basically want to check if two values are equal but its saying something about expression expected although i've given the expression to evaluate.
The above is a mix of vb.net and c# syntax. You can use either in .net with success but not both at the same time. Get rid of the { and } to stick with vb.
Looks like you are mixing C# and VB.Net. Assuming you are using VB.Net
Replace the '{' with Begin IF and remove the '}'.

Detecting null/empty input from user

How can I check if the user has input a null or empty string in classic-asp? Right now I am have this code.
If Request.Form("productId") == "" Then
'my code here
End If
But its not working.
Classic ASP/VBScript uses one = to check for equality, not two. Another thing you may want to try is
If Request.Form("productid") = "" Then
Code here
End If
It is a mess. Here's what I have found ...
(1) To look for existence in the QS, use if IsEmpty(x)=false (ie, URL?x)
(2) To look for a value in the QS, look for if x <> "" (ie, URL?x=anything)
Good luck!
If IsEmpty(Request.Form("inputPhoneNo")) = False Then
response.Write"<script language=javaScript>alert('Blank Phone Number');</script>"
response.Write"<script language=javascript>history.back()</script>"
Else
End If

Resources