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

  • SEARCH
  • Home
  • 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 8254225
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T01:07:08+00:00 2026-06-08T01:07:08+00:00

Summary: Disabled ASP.NET validators are losing their InnerHTML content when posted-back to the server,

  • 0

Summary:
Disabled ASP.NET validators are losing their InnerHTML content when posted-back to the server, and then when enabled (locally via JavaScript) show the ErrorMessage rather than original InnerHTML when fired.

More Details:
I deal with some complex forms that require lots of individual controls to be visible/invisible, and their validators to be enabled/disabled, depending on the selection of other controls.

All the validators contain an single “asterisk” image, with the error message shown via the central asp:ValidatorSummary object. For instance (formatted for viewing here, normally there is no whitespace UPDATE, this is not actually correct, please see update below)…

<asp:RequiredFieldValidator runat="server" ID="valName" 
  ControlToValidate="txtName" ErrorMessage="Enter a name">
    <img runat="server" src="~/images/error.gif" />
</asp:RequiredFieldValidator>

Rather than use asp:CustomValidator on every single validator (which requires local JavaScript and server-side handlers for each), I simply set .enabled = false on normal validators as part of the event handler for the “parent” control. (The status of the controls is also set on the server-side on the initial page load, as well as subsequent post-back page loads.)

function showName(show){
  document.getElementById("txtName").style.display = (show ? "" : "none");
  document.getElementById("valName").enabled = show;
}

The problem lies in the sequence of events where a validator is disabled, the form is posted-back… then a control is changed (via user interation) and the validator is enabled. If the validator now fails (on an attempted post-back) the <img code has gone, so instead it displays the ErrorMessage text where the image should be.

The InnerHTML remains as long as the validator stays enabled.

Other than dynamically adding the image to each validator on every single page load (which I really don’t want to do), or converting them all to CustomValidators (which again I really don’t want to do), does anybody know any way around this? Is this a known bug (because I can’t find anything obvious)?

I am using ASP.NET 2.0 under Visual Studio 2010 – unfortunately, not in a position at the moment to upgrade to a higher version of ASP.NET.

UPDATE
I have just discovered is that the <img tag is actually preceded by a &nbsp; entity… and if I remove that, leaving just the <img tag within the validator, it works.

After lots of playing, from what I can work out if the InnerHTML of the validator contains just plain text (i.e. no ASP server-side controls) then the InnerHTML will persist across post-backs no matter whether the validator is enabled or not.

However, if the InnerHTML starts with any plain text (other than whitespace) AND also has any server-side controls, then it does NOT persist across post-backs correctly when the validator is disabled.

I don’t understand why this is the case, but for the minor formatting issue I can certainly cope with it… either that, or I will have to put the &nbsp; inside a literal, or style the <img tag… plenty of different options on that one.

Using a ASP.NET 4.0 test-bed application, I can confirm that the same thing happens in that version.

If nobody had anything else they want to add in the next couple of days, I will “answer” the question myself with the above.

  • 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-06-08T01:07:10+00:00Added an answer on June 8, 2026 at 1:07 am

    As I stated in my updated question, the reason for the issue was due to the InnerHTML of the validator starting with &nbsp; and then containing a server-side control.

    Before I had it as…

    <asp:RequiredFieldValidator runat="server" ID="valName" ControlToValidate="txtName"
      ErrorMessage="Enter a name">&nbsp;<img runat="server" src="~/images/error.gif" 
      /></asp:RequiredFieldValidator>
    

    To fix it, I simply removed the &nbsp;…

    <asp:RequiredFieldValidator runat="server" ID="valName" ControlToValidate="txtName"
      ErrorMessage="Enter a name"><img runat="server" src="~/images/error.gif" 
      /></asp:RequiredFieldValidator>
    

    Hopefully that will help somebody else, in the unlikely event that they find themselves in a situation situation.

    As always, if somebody comes up with a different answer / solution, I’m always willing to reconsider my options.

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

Sidebar

Related Questions

Summary : synchronisation of multiple SQLite databases with server side sequentially. I'm working on
Summary I have written an Excel wrapper in .NET using Visual Basic and Visual
I want to disable a ASP.NET RequiredFieldValidator with JavaScript. Actually I'm using the following
I am working on a legacy web application written in VB.NET for ASP.NET 1.1.
Summary: I want a horizontal row of ImageButtons to scale down evenly to fit
Summary For some reason, git commands don't work the same when I am logged
Summary: I want to display a value (in a text box) stored in another
Summary: I have passed the name of the id select tag into an Array.
Summary : is there a way to get the unique lines from a file
Summary I am after some advice on the easiest way to analyze simple data

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.