Click here to Skip to main content
15,896,606 members
Please Sign up or sign in to vote.
3.50/5 (2 votes)
See more:
I have created the below-listed to disable a control if the values of two global variables do not match. However, the control is not being disable if the condition "exists." Furthermore, an error occurs. Thank you

VB
Private Sub DisableControls()
        Try

            If (obj.gblDestinationCountry <> "") And (obj.gblOriginCountry) <> "" And obj.gblOriginCountry <> obj.gblDestinationCountry  Then

                'txtReference1.Enabled = False


            End If

        Catch ex As Exception
            ScriptManager.RegisterStartupScript(Page, GetType(Page), "Error", "alert('An error occurred!');", True)
        End Try

    End Sub
Posted
Updated 21-May-14 15:23pm
v2
Comments
joshrduncan2012 21-May-14 17:19pm    
What is the error code and what line(s) is it pointing to? Remember, we can't see your screen.

1 solution

Why don't you try nested if's?

Example:
VB
Private Sub DisableControls()
Try
  If gblDestinationCountry <> "" and gblOriginCountry <> "" then
    If gblDestinationCountry <> gblOriginCountry then
      txtReference1.Enabled=False
    End If
  End If
Catch ex As Exception
  ScriptManager.RegisterStartupScript(Page, GetType(Page), "Error", "alert('An error occurred!');", True)
End Try
End Sub


<EDIT> Can you tell me in what line do you have an error? Maybe, we can work on that. </EDIT>
 
Share this answer
 
v2
Comments
Member 10835262 21-May-14 23:14pm    
"txtReference1" is contained in a FormTemplate. Referencing the control may be what is giving the error. Thank you for your anticipated response.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900