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 1051693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T16:58:33+00:00 2026-05-16T16:58:33+00:00

Basically, I have a custom templated control with a custom data container class. When

  • 0

Basically, I have a custom templated control with a custom data container class. When a developer adds an instance of my control to a page, they can define the controls in the LayoutTemplate however they like, as follows:

    <ml:MyControl id="MyControl1" runat="server">
        <LayoutTemplate>
            <span><%#Container.ErrorMessage%></span>
        </LayoutTemplate>
    </ml:MyControl>

This example renders on the page like this:

<span id="MyControl1"><span>
            <span>ml_errormessage</span>

        </span></span>

I would like my control to automatically move the “ml_errormessage” (databound content from Container.ErrorMessage – hard coded token in the property) to be a class of its containing element to make it easier for jQuery to use a selector to find the element and dynamically insert the error message client side. More importantly, I would like it moved out of the way so the class name doesn’t get replaced by the content and jQuery can find it as many times as it needs to during the page lifecycle. In other words, I would like the output to look like this without the developer changing the input template or resort to using custom controls in the template:

<span id="MyControl1"><span>
            <span class="ml_errormessage"></span>

        </span></span>

I would like to move the value using the controls collection rather than resorting to string parsing of the output, if possible. However, when I interrogate the collection in an override of OnPreRender, the control in the template looks like this in the debugger:

{System.Web.UI.DataBoundLiteralControl}
System.Web.UI.DataBoundLiteralControl: {System.Web.UI.DataBoundLiteralControl}
AppRelativeTemplateSourceDirectory: "~/"
BindingContainer: {MyControls.MyControlData}
ClientID: "MyControl1_ctl01_ctl00"
Controls: {System.Web.UI.EmptyControlCollection}
EnableTheming: True
EnableViewState: True
ID: "ctl00"
NamingContainer: {MyControls.MyControlData}
Page: {ASP.default_aspx}
Parent: {MyControls.MyControlData}
Site: Nothing
SkinID: ""
TemplateControl: {ASP.default_aspx}
TemplateSourceDirectory: "/MyControls"
UniqueID: "MyControl1$ctl01$ctl00"
Visible: True

As you can see the “ml_errormessage” value is nowhere to be found. Upon analysis of the DataBind event of the Control class using Reflector, I see that it delegates the binding behavior to each control. In other words, each control handles its own databinding. However, since I have no way of knowing in advance what control types will be in the template, how can this change be done?

Note: an acceptable alternative would be to add a new HtmlGenericControl (span) in the exact spot where the “ml_errormessage” is and add it as a class to this new control.

On a side note, is there an easy way to get the control’s output to indent for easy reading during debugging?

  • 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. Editorial Team
    Editorial Team
    2026-05-16T16:58:33+00:00Added an answer on May 16, 2026 at 4:58 pm

    Only seconds after posting this, I thought of an easy solution…simply hard code "<span class=""ml_errormessage""></span>" as the result of my container property ErrorMessage.

    Sure, it adds an extra unneccessary <span> element, but it also makes it safer if the end developer decides to put additional elements along with the databound value.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I would recommend updating the status any time the status… May 17, 2026 at 6:57 am
  • Editorial Team
    Editorial Team added an answer Worked it out after some help from a friend. I… May 17, 2026 at 6:57 am
  • Editorial Team
    Editorial Team added an answer The documentation for htmlTreeParse shows one method. Here's another: >… May 17, 2026 at 6:57 am

Trending Tags

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

Top Members

Related Questions

I have a custom Expander control called SpecialExpander . It is basically just a
I basically have a page which shows a processing screen which has been flushed
Basically I have the following class: class StateMachine { ... StateMethod stateA(); StateMethod stateB();
I have created a custom server control with properties implementing the ITemplate interface. It
I basically have the following flow: XML -> JSON -> Spring MVC -> jsp
I am looking in to ways to enable a site to basically have something
I would like to do the following. Basically have a stored procedure call another
Basically I have some code to check a specific directory to see if an
Basically I have a bunch of unmanaged VC++ static libraries. And the VC++ GUI
Basically I have a website. I have a properly setup sitemap so I assume

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.