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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T23:12:16+00:00 2026-05-10T23:12:16+00:00

Say you have something like an ASP.NET ASP:DetailsView to show and edit a single

  • 0

Say you have something like an ASP.NET ASP:DetailsView to show and edit a single record in a database.

It’s simple to record the error cases… you add validation and a validation summary. When your update form fails validation it naturally makes noise: it shows the validation message and/or the validation summary. Not a single code behind is required.

But then, you pass validation, and it makes your update completely silently. There’s no sense that anything happened, and there doesn’t seem to be any default settings to make a success message without code-behinds.

But, even code-behinds are confusing. What event should show the success message? onItemUpdate, right? Fine, but then let’s say you make another change and get a validation error? Your success message stays. I wasn’t able to find an event that would reliably turn off an existing success message if there were a validation error.

This should be web development 101! Why is it so hard?

EDIT:

Someone suggested using the ItemCommand event… I tried this and many other events, but that success message just won’t disappear. Here’s some code.

My message in ASP.NET

<label id='successMessage' class='successMessage' runat='server'></label> 

And my DataView tag (simplified):

    <asp:DetailsView          Id='EditClient'         DataKeyNames='LicenseID'      DataSourceID='MySource'     runat='server'          OnItemUpdated='SuccessfulClientUpdate'         OnItemCommand='ClearMessages'> 

And, my code-behind:

protected void SuccessfulClientUpdate(object sender, DetailsViewUpdatedEventArgs e) {     successMessage.InnerText = string.Format('Your changes were saved.');     successMessage.Visible = true; }  protected void ClearMessages(object sender, DetailsViewCommandEventArgs e) {     successMessage.InnerText = string.Empty;     successMessage.Visible = false; } 

Once I do a successful update, however, nothing seems to make that message disappear, not even failed validation.

2nd EDIT:

Just want to be clear that I did try putting the ClearMessages code in Page_Load. However, nothing seems to make that successMessage label disappear when I hit update a 2nd time WITH a validation error. Can anyone suggest any other troubleshooting tips?

  • 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-10T23:12:16+00:00Added an answer on May 10, 2026 at 11:12 pm

    As far as I know, there is no native way of doing this. You may rant about it, maybe Microsoft will hear it :).

    Resetting the ‘success message’ on Page_Load, or wherever in your code-behind, won’t work. This is because ASP.NET validation is usually done both client and server-side. This means for every validation control you put on the page, ASP.NET generates some client-side Javascript that does the validation and renders the error on the client, without going back to the server. So you’re stuck with both the success message and the error message at the same time.

    What you can do about it:

    • place a <div> control on your page, that would show up the success message (as already suggested by others above). Whenever you update something (in server-side code), show up the control and set a meaningful ‘Successful!’ message text.
    • register a custom Javascript function that would lookup the <div> and hide it on every page submit. Be aware that the function needs to be called before the autogenerated client script that does the validation.

    If you look at the client source of an ASP.NET page (with validators on it), here’s what you can find:

    <form name='aspnetForm' method='post' action='MyPage.aspx' onsubmit='javascript:return WebForm_OnSubmit();id='aspnetForm'>

    The WebForm_OnSubmit is generated by ASP.NET and calls the javascript that does the validation. Sample:

    function WebForm_OnSubmit() { if (typeof(ValidatorOnSubmit) == 'function' && ValidatorOnSubmit() == false)     return false; return true; } 

    To register your custom code that hides the success message, you should place (in your code-behind) something along these lines:

    if (!Page.ClientScript.IsOnSubmitStatementRegistered('ClearMessage')) {     string script = @'document.getElementById('' +          yourDivControl.ClientID + '').style.display='none'';     Page.ClientScript.RegisterOnSubmitStatement(Page.GetType(), 'ClearMessage', script); } 

    This will turn your page’s autogenerated WebForm_OnSubmit into the following:

    function WebForm_OnSubmit() {     document.getElementById('ctl00_yourDivControl').style.display='none';     if (typeof(ValidatorOnSubmit) == 'function' && ValidatorOnSubmit() == false)         return false;     return true; } 

    The effect: On every postback (e.g. when ItemCommand is triggered, or when some Save button is clicked, or anything else), you will show up the div control with the ‘success’ message. On the next postback, just before submitting the page to the server, this message is cleared. Of course, if this postback also triggers a ‘success’, the message is shown again by the code-behind on the server. And so on and so forth.

    I hope the above is helpful. It’s not the full-blown solution, but it gives sufficient hints to point you in the right direction.

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

Sidebar

Ask A Question

Stats

  • Questions 73k
  • Answers 73k
  • 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 Neural networks are classifiers. They separate two classes of data… May 11, 2026 at 1:57 pm
  • added an answer Briefly : Convert the shape into a bitmapData with the… May 11, 2026 at 1:57 pm
  • added an answer I'd use an active pattern to encapsulate the Regex.IsMatch and… May 11, 2026 at 1:57 pm

Related Questions

Say you have an application divided into 3-tiers: GUI, business logic, and data access.
Say you have 2 database servers, one database is the 'master' database where all
Say you have a shipment. It needs to go from point A to point
Say you have several webparts, one as a controller and several which take information
OK, I am now wondering how to handle navigation tabs with ASP.NET MVC. Giving
The title pretty much says it all. When I'm doing some reflection through my
I'm currently writing an ASP.Net app from the UI down. I'm implementing an MVP
When I first heard about StackOverflow, and heard that it was being built in

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.