The ParseChildren and PersistChildren attributes - Justin Lovell's Blog
in

dotnet.org.za

South African .NET Developer Portal

This Blog

Syndication

News

Search My Blog

<input class="BlogSearch" type="text" name="searchBox" id="blogSearchText" value="" onkeypress="return blogSearch(event, this);"> <input type="button" value="Search" onclick="return blogSearch2('blogSearchText');" class="BlogSearchButton">
Powered by Google

Justin Lovell's Blog

The Grumpy Coder

The ParseChildren and PersistChildren attributes

Q: In one of the articles that you wrote, you used the ParseChildren(false) and the PersistChildren(false) attributes on your web control class. What are they for? And why are the necessary?

 

A: Looking at the Microsoft documentation, I suppose you were confused on what these attributes are. I don’t blame you because the documentation assumes that you have quite a bit of experience. Essentially, these two attributes bitwise ‘switches’ which describes to ASP.NET on how to parse your control’s contents – the “contents” are what is found between the tags of your server control on your *.aspx or *.ascx files. Take for example the following code, of which, the contents are underlined.

 

<asp:Panel runat="server" ID="pnlSomePanel">

            <asp:Button runat="server" OnClick="SomeButton_Click" Text="Click Me"/>

</asp:Panel>

 

To simply put the above code into explanation of the ASP.NET parser does: the inner content is parsed as controls and is added to the panel’s control collection. You realize this because you probably do the above almost everyday. However, take the prior statement about what the ASP.NET parser does and break it down into actions. These actions are, in generic terms:

 

  1. Treat the inner content as …
  2. Persist the inner content to …

 

And these two actions, my friend, are what those two attributes are for describing the actions. To iterate through that list again but describing them to the attribute:

 

  1. ParseChildrenAttribute
  2. PersistChildrenAttribute

 

The argument in the ParseChildrenAttribute is there to describe whether or not the contents are treated as child properties or not (“true” for child properties and “false” for parsing the contents as server controls). The argument of the PersistChildrenAttribute is there to describe to the design time environment (for example, Visual Studio.NET) on how to persist the changes through the IDE – whether or not to persist it as child controls (“true” means they are persisted as server controls and “false” is not).

Comments

 

osman kibar said:

so sorry sir I  dont understand what PersistChildren means what it is for. there is no diffrence between using PersistChildren or not using it. actually what i want from u is to make it clear. because i am not good at comprehension.

April 22, 2009 6:21 PM

Leave a Comment

(required)  
(optional)
(required)  

Enter the numbers above:
Add
Powered by Community Server (Commercial Edition), by Telligent Systems