views:

551

answers:

2

I have followed this article on MSDN.

The template works fine but i got 2 big problems.

I can't access the controls in the template even if i decorate the template with these

[TemplateContainer(typeof(MessageContainer))]
[PersistenceMode(PersistenceMode.InnerProperty)]
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]

Second, I get a design time error which is really bad:

Error Creating Control - TemplateTest1
Type 'System.Web.UI.UserControl' does not have a public property named 'MessageTemplate'.

Now, why I want this is because user controls are great and easy, so i want to create user control that will produce this

 <div class="FormFiled">
--- here i want the ability to put controls that i want ----
<div class="Wrapper">
</div>
</div>

So if templating does not work, is there way to achieve this other than templating ?

Thanks in advance.

A: 

Where is the code of the template located? Is it in the App_Code folder does it belong to some namespace your page does not have a glue about ?

For example I use the following template

namespace GUI.Controls
{

public class GvTemplate : ITemplate

...

and in the code behind I have to call it as follows :

colField.ItemTemplate = new GUI.Controls.GvTemplate()

If you are not creating the template dynamically you would have to register the control at the top of the page ...

YordanGeorgiev
thanks for reply man, i am using website project, and no the control is not in APP_Code it is in a normal folder called ControlTemplate along with the test ASPX page.and i have followed exactly what the article suggested, no dynamic template, a replica of the article.
A: 

Can you post your code behind for the control? When you say you cannot access the controls in the template, what do you mean?

/Asger

asgerhallas
thanks, what i mean is i cant access he controls in the template from the page hosting the control directly, without using FindControl().plus the designer error is not going :(
No that will not be possible, you need to use FindControl. Think of what would happen if your user control repeated the controls - the controls in the template can not be seen as controls added to the page. Use FindControl - maybe recusively.
asgerhallas