Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As far as I know, there is no native way of doing this. You may rant about it, maybe Microsoft will hear it :).</p> <p>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, <strong>without</strong> going back to the server. So you're stuck with both the success message and the error message at the same time.</p> <p>What you can do about it:</p> <ul> <li>place a <code>&lt;div&gt;</code> 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.</li> <li>register a custom Javascript function that would lookup the <code>&lt;div&gt;</code> 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.</li> </ul> <p>If you look at the client source of an ASP.NET page (with validators on it), here's what you can find:</p> <p><code>&lt;form name="aspnetForm" method="post" action="MyPage.aspx" onsubmit="javascript:return WebForm_OnSubmit();id="aspnetForm"&gt;</code></p> <p>The WebForm_OnSubmit is generated by ASP.NET and calls the javascript that does the validation. Sample:</p> <pre><code>function WebForm_OnSubmit() { if (typeof(ValidatorOnSubmit) == "function" &amp;&amp; ValidatorOnSubmit() == false) return false; return true; } </code></pre> <p>To register your custom code that hides the success message, you should place (in your code-behind) something along these lines:</p> <pre><code>if (!Page.ClientScript.IsOnSubmitStatementRegistered("ClearMessage")) { string script = @"document.getElementById('" + yourDivControl.ClientID + "').style.display='none'"; Page.ClientScript.RegisterOnSubmitStatement(Page.GetType(), "ClearMessage", script); } </code></pre> <p>This will turn your page's autogenerated WebForm_OnSubmit into the following:</p> <pre><code>function WebForm_OnSubmit() { document.getElementById('ctl00_yourDivControl').style.display='none'; if (typeof(ValidatorOnSubmit) == "function" &amp;&amp; ValidatorOnSubmit() == false) return false; return true; } </code></pre> <p>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.</p> <p>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.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload