Bohn
Bohn

Reputation: 26919

Having very similar HTML in both IF and ELSE clause

There is a page that has a bunch of elements like this in its code behind:

                    <%
    If (someBoolean) Then
                    %>
<textarea name="txtSomeThing" tabindex="1" id="txtSomeThing" style="overflow: auto;" rows="12" cols="80"></textarea>

Now I am introducing another boolean variable lets name it someOtherBoolean and ElseIF that one is true I want the same HTML as above with only one difference: adding a readonly attribute to it. So I copy pasted it in an else clause and added the readonly but VS errors on it because it think the page cannot have two elements with the same ID.
How can I fix this issue?

Upvotes: 0

Views: 25

Answers (1)

nobody
nobody

Reputation: 11080

You cannot have two elements with the same Id.You can use the boolean in the attribute value like this

<%
    If (someBoolean) Then
%>
<textarea 
         name="txtSomeThing" 
         tabindex="1" 
         id="txtSomeThing" 
         style="overflow: auto;" 
         rows="12" 
         cols="80"
         readonly="<%# someOtherBoolean %>">
</textarea>

Upvotes: 1

Related Questions