Hi folks
I'm building an FAQ page where the answers to questions are displayed when the question is clicked on. I've got a repeater on the page like so:
<asp:Repeater ID="rptFAQ" runat="server">
<HeaderTemplate>
<ol>
</HeaderTemplate>
<ItemTemplate>
<li>
<a href="#<%# Eval("strIndex") %>"><%# Eval("strQuestion") %></a>
<asp:PlaceHolder ID="phAnswer<%# Eval("strIndex") %>" runat="server"><%# Eval("strAnswer") %></asp:PlaceHolder>
</li>
</ItemTemplate>
<FooterTemplate>
</ol>
</FooterTemplate>
</asp:Repeater>
But alas, on the PlaceHolder line I receive the following error:
------------------
Parser Error
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.
Parser Error Message: The server tag is not well formed.
Source Error:
Line 13: <li>
Line 14: <a href="#<%# Eval("strIndex") %>"><%# Eval("strQuestion") %></a>
Line 15: <asp:PlaceHolder ID="phAnswer<%# Eval("strIndex") %>" runat="server"><%# Eval("strAnswer") %></asp:PlaceHolder>
Line 16: </li>
Line 17: </ItemTemplate>
------------------
The variable strIndex is simply a integer converted to a string. It works happily in the href, but doesn't like forming part of the ID in the PlaceHolder. The same thing happens if I use a div with the runat="server" attribute (but it doesn't error if I remove runat="server").
I've seen some suggestions that this may be fixed by using single or no quotes around the ID (i.e. ID='<%# "phAnswer" + Eval("strIndex") %>' ), but that gives me a different error. As follows:
Parser Error Message: 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" />
Anyway, I was hoping that I could built the FAQ page to cater for users with scripting turned off (hence my wish to include runat="server" tag). Does anyone have any ideas? This is really annoying me.
Start Free Trial