Reputation:
I'm trying to render an element's mark-up using asp controls while avoiding using code-behind. So I want to dynamically generate the href property to include what is rendered from a FieldValue control (SharePointWebControls).
So for example this control I have:
<SharePointWebControls:FieldValue id="PageTitle" FieldName="Title" runat="server"/>
Appears as:
"TestPage"
And I have a link on that same page looking like this:
<a href="http://www.mysite.com/mypage.aspx?title=TestPage">CLICK HERE!</a>
But above in the <a>
element - I need TestPage to be there as a result of what's rendered by my FieldValue
control; so I basically need a way of 'embedding' the output of this control within the <a>
element's href property.
There's no messy bits of markup to accompany the rendered version of FieldValue
- it's literally just text - so I'm assuming this isn't complicated.
Upvotes: 0
Views: 795
Reputation: 15413
Not familiar with SP controls, but I guess the compiler stops on the double quotes when you try to embed you control in the href.
Maybe you can try replacing you href's double quotes with single quotes like this :
<a href='http://www.mysite.com/mypage.aspx?title=<SharePointWebControls:FieldValue id="PageTitle" FieldName="Title" runat="server"/>'>CLICK HERE!</a>
( be aware that it will fail if there are quotes in your text )
another solution I see is using some js/jquery (almost the same solution, in fact) :
$('selectorForYourA').attr("href", 'http://www.mysite.com/mypage.aspx?title=<SharePointWebControls:FieldValue id="PageTitle" FieldName="Title" runat="server"/>');
Upvotes: 1