How to create two ContentPlaceHolder with the same ID in ASP.NET?
I don't want to have two master pages so I'm trying to do this (left out the <% %> for readability):
if (a == b)
{
开发者_如何转开发<asp:ContentPlaceHolder ID="X" runat="server" />
}
else
{
<div class="c">
<asp:ContentPlaceHolder ID="X" runat="server" />
</div>
}
But it won't let me:
Duplicate ContentPlaceHolder 'X' were found. ContentPlaceHolders require unique IDs.
So I tried to set the IDs with ID="<%= "X" %>" and no, won't let me either:
Server tags cannot contain <% ... %> constructs.
Then I tried <%# Eval("X") %> and nope:
The ID property of a control can only be set using the ID attribute in the tag and a simple value. Example: <asp:Button runat="server" id="Button1" />
Is there any way to achieve what I'm trying to do? I was thinking something like
echo '<asp:ContentPlaceHolder ID="X" runat="server" />'
Or some dynamic way to add the tag because apparently the parser can't identify the if else block which won't let two tags have the same ID.
I'm using MVC with the default view engine.
Have you tried like this:
<% var isAEqualB = a == b; %>
if (isAEqualB)
{
<div class="c">
}
<asp:ContentPlaceHolder ID="X" runat="server" />
if (isAEqualB)
{
</div>
}
精彩评论