Javascript and Required field validator
<p>I have a RequiredFieldValidator on a TextBox. This works fine when nothing is enterd in the TextBox. Now, one more validation I do is when the user enters some junk data, I throw an error-message saying "invalid entry". This is on the Label.</p>

<p>Now the scenario is after the error-message is thrown, if the user empties the textbox and clicks on the button, the RequiredFieldValidator works but the error-message on the label still remains as it is. I would like to hide/remove it once the user empties the textbox.</p>

<p>For this I used a JavaScript function but with this the RequiredFieldValidator does not work. Here's my code: </p>

<pre><code>&lt;asp:TextBox ID="txtemp" runat="server"&gt;&lt;/asp:TextBox&gt;
&lt;asp:Button ID="btnstatus" runat="server"  ValidationGroup="valgrp1" OnClientClick="Validate()"
    CausesValidation="true"  onclick="btnstatus_Click" 
    Text="Fetch status message" BackColor="#ccebff" /&gt;
&amp;nbsp;
&lt;asp:RequiredFieldValidator ID="Reqfield1" ControlToValidate="txtportalid"  ValidationGroup="valgrp1" ErrorMessage="wrong entry" runat="server" /&gt;
&lt;/div&gt;
&lt;div&gt;
    &lt;asp:Label ID="lblerrormsg" runat="server"  Font-Bold="true"  Visible="false" ForeColor="#FF3300"&gt;
    &lt;/asp:Label&gt;
&lt;/div&gt;
</code></pre>

<p>JavaScript:</p>

<pre><code>function Validate()
{
    var txt1 = document.getElementById("&lt;%= Txtemp.ClientID %&gt;");
    var val1 = txt1.value.replace(/\s/g, "");

    if (val1=="")
    {
        document.getElementById("&lt;%= lblerrormsg.ClientID%&gt;").style.display = 'none';
    }
}
</code></pre>
