I'm having a heck of a time figuring out how to write code that uses server controls such as asp:panel and asp:literal and renders valid xhtml. I'm hoping someone can give me some pointers, or tell me it's not possible, and to just quit trying. Here is the problem I'm working on.
At this website, http://checkoutacollege.com/ReadySetGo/Ready/Ready.aspx, the short list item menu that includes the "Email" and the "Print" links is a user control. Some pages have both links, some only have one. The links are displayed or not using attributes set to true or false like this:
<uc2:ucEmailContent id="ucEmailThisPage" runat="server" EmailVisible="true" PrintVisible="true" ></uc2:ucEmailContent> .
The .ascx page for the user control creates an <ul> with two <li> like this:
<ul>
<li>
<asp:Panel ID="pnlEmailThisPage" runat="server">
<asp:LinkButton ID="lnkBtnEmailThisPage" runat="server" OnClick="lnkBtnEmailThisPage_Click" Text="Email">
</asp:LinkButton>
|
</asp:Panel>
</li>
<li>
<asp:Panel ID="pnlPrintThisPage" runat="server">
<a href="javascript:window.print()">
<asp:Literal ID="litPrint" runat="server" Text="Print"></asp:Literal></a>
</asp:Panel>
</li>
</ul>
The problem with this, is that if the Email or the Print link is not set to be visible on a particular page, then it renders as an empty <li>.
I tried putting the <li> in an <asp:literal> where I could control its visibility or not, but I got an error message that I can't have "text" (the <li> written with the literal) inside of a <ul>.
I can put the <li> inside the asp:panel, but the use of the asp:panel itself is a problem since it renders as a <div> inside of the <ul> which isn't valid either.
Anyone have any ideas how I can approach this so that it will render valid code? Is it possible?