OnclientClick of a button I hide a panel client side. I only want to hide it however if all input is valid. Is this possible in Javascript?
A:
You would have to call the page validation functions manually. You can call the Page_ClientValidate(validationGroup) function to check a specific group. For a complete reference you can check out the WebUIValidation.js file that is output by .NET 1.1.
cnobles
2009-10-15 19:22:06
+1
A:
You can use the Page_IsValid
property, it allows you to check whether the entire form is valid. You must call the Page_ClientValidate
function before checking the value of Page_IsValid
. This function is responsible for setting the value of the Page_IsValid
property.
<asp:Panel ID="pnl" runat="server">
<asp:Button ID="btn" runat="server" Text="Click" OnClientClick="return Validate();" CausesValidation="false" />
<script type="text/javascript">
function Validate()
{
if (typeof(Page_ClientValidate) == 'function')
Page_ClientValidate();
var panel = document.getElementById('pnl');
if(Page_IsValid)
panel.style.display = 'none';
else
panel.style.display = 'block';
return false;
}
</script>
Phaedrus
2009-10-22 03:11:42