Condition to check null variables does not work

Asked

Viewed 107 times

4

I’m developing a page ASP (Classic) and on that page I have this:

<%if(textocontrato) = "NULL" Then%>
<td >Texto Contrato</td>
<td ><input type="text" name="textocontrato" value="<%=textocontrato%>" size=30 maxlength=30></td>
<%Else %>
<td >Texto Contrato</td>
<td ><input type="text" name="textocontrato" value="<%=Server.HTMLEncode(textocontrato)%>" size=30 maxlength=30></td>
<%End If%>

What I want is that if the textocontrato for = NULL executes the HTML top if it’s not NULL runs the bottom, however even when the textocontrato is null he runs the bottom and ends up giving me error, for the Htmlencode You’re not getting anything. What am I doing wrong?

  • 3

    Have you tried <%If IsNull(textocontrato) Then%>?

1 answer

10


You can try this 3 ways.

1st Way:

<%If IsNull(textocontrato) Then%>

2nd way:

<%If (textocontrato) == null Then%> //Note que null não tem aspas

3rd Way:

<%If (textocontrato) == "" Then%>
  • 1

    Thanks, I used the first way and it worked!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.