Unfortunately, the ITemplate property setters are called in a different order than the template tags in the markup. The parser seems to see a Tem1 tag first, so it runs a setter for all the Tem1 tags, then for all the Tem2 tags. The result is: First, Third,
Second, Fourth.
Is there a way to retain the order of template tags when their setters are called, or alternately a way within the setter to find the location in the aspx of the tag that initiated the setter? Or am I missing something?
Is there a way to retain the order of template tags when their setters are called, or alternately a way within the setter to find the location in the aspx of the tag that initiated the setter? Or am I missing something?
Hello:)
Not very clear about what you say……
Would you mind showing us your screenshot about the actual result and plz tell us what you are expecting....
using System.Collections.Generic;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace CustomTagTest1
{
[ParseChildren(true), PersistChildren(false)]
public class CustomTag : WebControl
{
private List<ITemplate> list = new List<ITemplate>();
[PersistenceMode(PersistenceMode.InnerProperty)]
[TemplateContainer(typeof(TemplateInstance))]
public ITemplate Template1 { set { list.Add(value); } }
[PersistenceMode(PersistenceMode.InnerProperty)]
[TemplateContainer(typeof(TemplateInstance))]
public ITemplate Template2 { set { list.Add(value); } }
protected override void CreateChildControls()
{
foreach (ITemplate t in list)
{
TemplateInstance i = new TemplateInstance();
t.InstantiateIn(i);
Controls.Add(i);
}
}
}
public class TemplateInstance : WebControl, INamingContainer
{
protected override void Render(HtmlTextWriter writer) { RenderContents(writer); }
}
Expected Result:
FirstSecondThirdFourth
Actual Result:
FirstThirdSecondFourth
I would expect the parser to run the ITemplate setters in the order they exist in the markup, but it doesn't. I can provide a more real-world example if this doesn't help clarify things.
None
0 Points
2 Posts
ITemplate parsing order issue
Aug 12, 2011 06:49 PM|Owen Byrne|LINK
Hi there,
I've created a custom server control with a few ITemplate inner properties. I'd like to allow for mixed use of these template tags like this:
Unfortunately, the ITemplate property setters are called in a different order than the template tags in the markup. The parser seems to see a Tem1 tag first, so it runs a setter for all the Tem1 tags, then for all the Tem2 tags. The result is: First, Third, Second, Fourth.
Is there a way to retain the order of template tags when their setters are called, or alternately a way within the setter to find the location in the aspx of the tag that initiated the setter? Or am I missing something?
Thanks very much.
All-Star
94130 Points
18109 Posts
Re: ITemplate parsing order issue
Aug 13, 2011 11:48 PM|Decker Dong - MSFT|LINK
Hello:)
Not very clear about what you say……
Would you mind showing us your screenshot about the actual result and plz tell us what you are expecting....
Thx again
None
0 Points
2 Posts
Re: ITemplate parsing order issue
Aug 15, 2011 05:04 PM|Owen Byrne|LINK
Hi there,
Here's an example:
index.aspx:
CustomTag.cs:
Expected Result:
Actual Result:
I would expect the parser to run the ITemplate setters in the order they exist in the markup, but it doesn't. I can provide a more real-world example if this doesn't help clarify things.
Thanks again!
Contributor
2244 Points
855 Posts
Re: ITemplate parsing order issue
Aug 17, 2011 12:16 AM|jkirkerx|LINK
There not custom tags
It's a control collection.
You have to build a control collection to properly access the internal tags. It takes about 3 pages of code to construct.
Google control collection for more information. I would list examples, but it would be like 10 feet long in space.