views:

28

answers:

2

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?

+2  A: 

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), before OnRender:

// In onload, pre render or other event handler 
MyControl1.SomeProperty = somevalue; // C#

MyControl1.SomeProperty = somevalue ' VB.NET
Oded
Dont want to do that, want to keep things simple, but thanks for the clarification!
joeriks
A: 

Try assigning the value of the property to a Label and call the .DataBind() method on the control.

citronas
Databinding works better in this sense yes. Thanks. However it requires some extra code over the code blocks.
joeriks