Literal control rendering empty

P

paul.hester

Hi all,

I have a custom control with an overridden Render method. Inside this
method I'm rendering each control in its collection using their
RenderControl method. However, I'm running into a problem in this
scenario:

<myprefix:mycontrol runat="server">
<%= SomeVariable %>
</myprefix:mycontrol>

The contained control is showing up in the control collection as a
LiteralControl, but its Text property is empty. Well, it's a series of
spaces, so it's not showing up with any content. I can put <%=
SomeVariable %> anywhere outside my custom control and it will render
the variable value correctly.

Is there anything I can do to ensure the variable value is rendered?

I hope this post makes sense!

Thanks,

Paul
 
A

Alessandro Zifiglio

hi Paul, it is my thinking that the expression is already written out to the
output stream, and that the evaluation of the expression is not deposited in
the containing .aspx page at a suitable time for usage by your control and
as such cannot make much use of it.
Reference msdn online about this particular inline code construct here :
http://msdn2.microsoft.com/en-us/library/6dwsdcf5.aspx

If you want to simply support adding text in btw your controls tags or
support nesting of child elements, then you want to make a new class that
inherits the ControlBuilder and associate your custom control with this.
Here is an example of how to use the ControlBuilder :
http://msdn2.microsoft.com/en-us/library/system.web.ui.controlbuilder.aspx

Regards,
Alessandro Zifiglio
http://www.AsyncUI.net
 
A

Alessandro Zifiglio

Auto-Correction :
You are unable to get the value of the inline codeblocks expression syntax
<%= %> since the default ControlBuilder does not pass back anything.
Instead, on the other hand, the built in ControlBuilder has support for
databinding expression syntax<%# %> allowing you to retrieve this value. It
makes the value available as a DataBoundLiteralControl. Note that to get the
value, it needs to added to your controls, control collection first, and
then reference the control in the collection in a phase after the
DataBinding phase in your controls life cycle.

Regards,
Alessandro Zifiglio
http://www.AsyncUI.net
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,815
Latest member
treekmostly22

Latest Threads

Top