Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VB.NET aspx page use codebehind variable in If statement

Tags:

asp.net

vb.net

I am trying to use codebehind variable in if statement. This is my statement.

<title><%If ("<%= title_tag%>".ToString().Contains("MI") = True) Then%>
        MI
   <% Else %>
        MC
    <%End If %>
</title>

But If I remove the codebehind variable and just use

<title><%If ("Home Care MI".ToString().Contains("MI") = True) Then%>
        MI
   <% Else %>
        MC
    <%End If %>
</title>

It works well. I've also tried escaping codebehind variable in two curly braces but it didn't help.

like image 224
Chirag K Avatar asked Aug 01 '26 02:08

Chirag K


2 Answers

I finally came through. Thanks for your support. I think the issue was in contains and tostring function.

<title><%IF title_tag = "Earlier Title" Then%>
            MI      
        <% Else %>
        MC
        <%End If %>
        </title> 
like image 151
Chirag K Avatar answered Aug 03 '26 19:08

Chirag K


Make sure you declare the variable as public in your code behind file and no need to use <% or " around variales...

<title><%If (title_tag.ToString().Contains("MI") = True) Then%>
        MI
   <% Else %>
        MC
    <%End If %>
</title>
like image 28
Jones Joseph Avatar answered Aug 03 '26 19:08

Jones Joseph