Removing Labels When Using Validation Controls

A

Andrew Lawson

Hi,

I have created a user administration form.

When the user clicks the save button, validation is done using various
validation controls, a procedure is then run to save the data.

At this point the same screen is shown (which is what I want, rather
than redirecting elsewhere), and I have a label which was invisible,
but is now visible and reads "Changes Saved".

This all works perfectly.

However, at this point the user may decide to again change the value of
a field. If that change means that something is no longer validated,
the validation controls kick in again and display an error message - as
you would expect, and this is great.

The problem is, the "Changes Saved" label is still displayed.

Is there a way to make the label invisible whenever the user clicks the
save button, before any validation messages are shown.

As in interim method I am instead displaying a pop-up to confirm it,
but the way it works now looks much more professional - as long as the
"Changes Saved" goes away.

Any help is appreciated.

Andrew.
 
K

Ken Cox [Microsoft MVP]

Hi Andrew,

I'm wondering if your problem stems from using client-side validation.
There's no trip to the server to remove the unwanted text from the label.

Here's a little sample of how you might want to accomplish this. Not sure,
but worth a try?

Private Sub Button1_Click _
(ByVal sender As Object, ByVal e As _
System.EventArgs) Handles Button1.Click
Label1.Text = IIf(Page.IsValid, _
"Changes Saved", "")
End Sub


<form id="Form1" method="post" runat="server">
<p>
<asp:textbox id="TextBox1" runat="server"></asp:textbox>
<asp:requiredfieldvalidator id="RequiredFieldValidator1"
runat="server" ControlToValidate="TextBox1"
ErrorMessage="RequiredFieldValidator"
EnableClientScript="False"></asp:requiredfieldvalidator></p>
<p>
<asp:button id="Button1" runat="server"
Text="Button"></asp:button></p>
<p>
<asp:label id="Label1" runat="server">Label</asp:label></p>
</form>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,141
Messages
2,570,818
Members
47,367
Latest member
mahdiharooniir

Latest Threads

Top