I tried using a codeblock syntax within a property sent to a web user control:
<uc1:MyControl ID="MyControl1" runat="server" SomeProperty="<%= somevalue %>"/>
The user control has the public property SomeProperty declared and also uses code block to display the property value:
<p><% = SomeProperty %></p>
The output on my page is unfortunately
<p><%= somevalue %></p>
And not the actual value. Anyone know of some workaround for this?
You are trying to assign a server side value on a server side control – this is not possible.
You can use code blocks in client side code (that doesn’t have a
runat="server"attribute), this of course doesn’t not apply to server side controls.Set the attribute in the code behind (
ascx), beforeOnRender: