Having a web form with numerous controls and a submit button can be tricky. The issue arises when a user initially submits clean data, resulting in the display of a "form submitted successfully" message using an asp.net label control. However, if the same user later enters invalid values for certain fields on the form and clicks submit again, both the success message and validation error messages are displayed.
The challenge now is how to eliminate the success message in this situation so that only the client-side validation error messages are shown. This may require some knowledge of JavaScript, which I don't have expertise in.
<asp:Button ID="btnAddActivity" Text="Add Activity" runat="server" onclick="btnAddActivity_Click" ValidationGroup="vgSetup" OnClientClick=" return changeLabel();"/>
<asp:Label ID="lblMessage" visible="false" ForeColor="red" runat="server"></asp:Label>
function changeLabel()
{
document.getElementById('<%= lblMessage.ClientID %>').innerHTML = "";
return;
}
Attached is the markup for the label and button. Attempting to call a JavaScript function during the OnClick event effectively disables the success message, but it unfortunately results in the validation error messages appearing after a post back. Ideally, I would like the validation error messages to show without requiring a post back. Any assistance or guidance on resolving this issue would be greatly appreciated.