I am creating a new literal control from code behind, I add standard html into it which works fine. I try to add <%= SomeDiv.ClientID %> into this literal control but it quite literally prints into source exactly whats in code behind.
Code behind:
new LiteralControl("<div id='" + paneID.Replace(" ", "") + "_Expand' runat='server' onclick='ChangePanelHeader('<%= " + paneID.Replace(" ", "") + "_Expand.ClientID %>'" + ", " + "'<%= " + paneID.Replace(" ", "") + "_cpe.ClientID %>')' class='rhsCollapsiblePanelsHeader'>" + paneTitle + "<br /><br /></div>" + paneContent)
In Browser Source once page is loaded:
<div id='Tellafriend_Expand' runat='server' onclick='ChangePanelHeader('<%= Tellafriend_Expand.ClientID %>', '<%= Tellafriend_cpe.ClientID %>')' class='rhsCollapsiblePanelsHeader'>Tell a friend<br /><br /></div>
Wanted result:
<div id='Tellafriend_Expand' runat='server' onclick='ChangePanelHeader("MyTelAFriendID_Expand", "MyTelAFriendID_cpe") class='rhsCollapsiblePanelsHeader'>Tell a friend<br /><br /></div>
Firefox syntax error:
syntax error
[Break On This Error]
ChangePanelHeader(<%= Tellafriend_Expand.ClientID %>, <%= Tellafriend_cpe.Cli...
default.aspx (line 1, col 20)
(After my initial “Huh?”) I notice you’re getting your server-side code to output ids that are not wrapped in quotes. In JS those ids likely need to be treated as strings, so try this:
(If that’s not it, well, I’ll wait for the question rewrite promised in your comment.)