Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 76855
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T20:44:20+00:00 2026-05-10T20:44:20+00:00

I’m setting up a User Control driven by a XML configuration. It is easier

  • 0

I’m setting up a User Control driven by a XML configuration. It is easier to explain by example. Take a look at the following configuration snippet:

<node>   <text lbl='Text:'/>   <checkbox lbl='Check me:' checked='true'/> </node> 

What I’m trying to achieve to translate that snippet into a single text box and a checkbox control. Of course, had the snippet contained more nodes more controls would be generated automatically.

Give the iterative nature of the task, I have chosen to use Repeater. Within it I have placed two (well more, see bellow) Controls, one CheckBox and one Editbox. In order to choose which control get activate, I used an inline switch command, checking the name of the current configuration node.

Sadly, that doesn’t work. The problem lies in the fact that the switch is being run during rendering time, long after data binding had happened. That alone would not be a problem, was not for the fact that a configuration node might offer the needed info to data bind. Consider what would happen if the check box control will try to bind to the text node in the snippet above, desperately looking for it’s ‘checked’ attribute.

Any ideas how to make this possible?

Thanks, Boaz

Here is my current code:

Here is my code (which runs on a more complex syntax than the one above):

<asp:Repeater ID='settingRepeater' runat='server'>         <ItemTemplate>            <%                switch (((XmlNode)Page.GetDataItem()).LocalName)               {                  case 'text':            %>            <asp:Label ID='settingsLabel' CssClass='editlabel' Text='<%# XPath('@lbl') %>' runat='server' />            <asp:TextBox ID='settingsLabelText' Text='<%# SettingsNode.SelectSingleNode(XPath('@xpath').ToString()).InnerText %>'               runat='server' AutoPostBack='true'  Columns='<%#  XmlUtils.OptReadInt((XmlNode)Page.GetDataItem(),'@width',20) %>'               />            <% break;                  case 'checkbox':            %>            <asp:CheckBox ID='settingsCheckBox' Text='<%# XPath('@lbl') %>' runat='server'                          Checked='<%# ((XmlElement)SettingsNode.SelectSingleNode(XPath('@xpath').ToString())).HasAttribute(XPath('@att').ToString()) %>'             />           <% break;               } %>            &nbsp;&nbsp;         </ItemTemplate>      </asp:Repeater> 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T20:44:20+00:00Added an answer on May 10, 2026 at 8:44 pm

    One weekend later, here is what I came with as a solution. My main goal was to find something that will both work and allow you to keep specifying the exact content of the Item Template in markup. Doing things from code would work but can still be cumbersome.

    The code should be straight forward to follow, but the gist of the matter lies in two parts.

    The first is the usage of the Repeater item created event to filter out unwanted parts of the template.

    The second is to store decisions made in ViewState in order to recreate the page during post back. The later is crucial as you’ll notice that I used the Item.DataItem . During post backs, control recreation happens much earlier in the page life cycle. When the ItemCreate fires, the DataItem is null.

    Here is my solution:

    Control markup

     <asp:Repeater ID='settingRepeater' runat='server'              onitemcreated='settingRepeater_ItemCreated'            >         <ItemTemplate>              <asp:PlaceHolder  ID='text' runat='server'>                   <asp:Label ID='settingsLabel' CssClass='editlabel' Text='<%# XPath('@lbl') %>' runat='server' />                   <asp:TextBox ID='settingsLabelText'  runat='server'                       Text='<%# SettingsNode.SelectSingleNode(XPath('@xpath').ToString()).InnerText %>'                      Columns='<%#  XmlUtils.OptReadInt((XmlNode)Page.GetDataItem(),'@width',20) %>'                     />              </asp:PlaceHolder>             <asp:PlaceHolder ID='att_adder' runat='server'>                <asp:CheckBox ID='settingsAttAdder' Text='<%# XPath('@lbl') %>' runat='server'                              Checked='<%# ((XmlElement)SettingsNode.SelectSingleNode(XPath('@xpath').ToString())).HasAttribute(XPath('@att').ToString()) %>'                 />             </asp:PlaceHolder>       </ItemTemplate>   </asp:Repeater> 

    Note: for extra ease I added the PlaceHolder control to group things and make the decision of which controls to remove easier.

    Code behind

    The code bellow is built on the notion that every repeater item is of a type. The type is extracted from the configuration xml. In my specific scenario, I could make that type to a single control by means of ID. This could be easily modified if needed.

     protected List<string> repeaterItemTypes    {       get       {          List<string> ret = (List<string>)ViewState['repeaterItemTypes'];          if (ret == null)          {             ret = new List<string>();             ViewState['repeaterItemTypes'] = ret;          }          return ret;       }    }     protected void settingRepeater_ItemCreated(object sender, RepeaterItemEventArgs e)    {       string type;       if (e.Item.DataItem != null)       {          // data binding mode..          type = ((XmlNode)e.Item.DataItem).LocalName;          int i = e.Item.ItemIndex;          if (i == repeaterItemTypes.Count)             repeaterItemTypes.Add(type);          else             repeaterItemTypes.Insert(e.Item.ItemIndex, type);       }       else       {          // restoring from ViewState          type = repeaterItemTypes[e.Item.ItemIndex];       }        for (int i = e.Item.Controls.Count - 1; i >= 0; i--)       {          if (e.Item.Controls[i].ID != type) e.Item.Controls.RemoveAt(i);       }    } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 70k
  • Answers 70k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer You're needing this one, assuming you're running Sitecore v6 or… May 11, 2026 at 12:54 pm
  • added an answer I suspect your trouble is due to the Initialize function.… May 11, 2026 at 12:54 pm
  • added an answer Paging with ASP.NET MVC Demo (source: taiga.nl) May 11, 2026 at 12:54 pm

Related Questions

I keep getting tasks that are above my skill level. How can I address this without coming accross as grossly incompetent?
I have a web-service that I will be deploying to dev, staging and production.
I'm thinking of starting a wiki, probably on a low cost LAMP hosting account.
I have the following tables in my database that have a many-to-many relationship, which
I'm using the RESTful authentication Rails plugin for an app I'm developing. I'm having
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am currently running into a problem where an element is coming back from
Seemingly simple, but I cannot find anything relevant on the web. What is the
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.