Re: validation in asp.net
Code:
<script language="JavaScript">
document.all["buttonName"].onclick = new function("Page_ValidationActive=true;");
</script>
Page.Validate()
If Page.IsValid Then
Lblerror.text = "your custom error message"
If Validationsummary1.Visible = True Then
Validationsummary1.Visible = False
End If
Else
If Validationsummary1.Visible = False Then
Validationsummary1.Visible = True
lblError.Text = ""
End If
End If
Re: validation in asp.net
CompareValidator1.aspx font size: 1 2 3 4 5 6 7
View Sample
Code:
<%@ Page clienttarget=downlevel %>
<html>
<head>
<title>CompareValidator Example</title>
<link rel="stylesheet" href="/aspxtreme/shared/netdemos.css">
<script language="C#" runat="server">
void ValidateBtnClick ( object src, EventArgs e ) {
if ( Page.IsValid ) {
lblMessage.Text = "Comparison is valid!";
}
else {
lblMessage.Text = "Comparison is not valid!";
}
}
void lstOperator_SelectedIndexChanged ( object src, EventArgs e ) {
comp1.Operator= ( ValidationCompareOperator ) lstOperator.SelectedIndex;
comp1.Validate ( );
}
</script>
</head>
<body>
<!-- #include virtual="~/shared/top.inc -->
<div class="header"><h3>CompareValidator Example</h3></div>
<hr size=1 width=90%>
<p>Type a value in each textbox, select a comparison operator, then click "Validate" to test. </p>
<form runat="server">
<div align="center">
<table bgcolor="#eeeeee" cellpadding=10>
<tr valign="top">
<td><h5>String 1:</h5>
<asp:textbox selected id="txtComp" runat="server"></asp:textbox>
<br>
<asp:requiredfieldvalidator
controltovalidate="txtComp"
errormessage="Field cannot be blank" runat="server" />
</td>
<td><h5>Comparison Operator:</h5>
<asp:listbox id="lstOperator" onSelectedIndexChanged="lstOperator_SelectedIndexChanged" runat="server">
<asp:listitem selected value="Equal">Equal</asp:listitem>
<asp:listitem value="NotEqual">NotEqual</asp:listitem>
<asp:listitem value="GreaterThan">GreaterThan</asp:listitem>
<asp:listitem value="GreaterThanEqual">GreaterThanEqual</asp:listitem>
<asp:listitem value="LessThan">LessThan</asp:listitem>
<asp:listitem value="LessThanEqual">LessThanEqual</asp:listitem>
</asp:listbox></td>
<td>
<h5>String 2:</h5>
<asp:textbox id="txtCompTo" runat="server"></asp:textbox>
<br>
<asp:requiredfieldvalidator
controltovalidate="txtCompTo"
errormessage="Field cannot be blank" runat="server" />
</td></tr>
</table>
<br>
<asp:button runat="server"
text="Validate" onClick="ValidateBtnClick" />
<br>
<asp:comparevalidator id="comp1"
controltovalidate="txtComp"
controltocompare="txtCompTo"
type="String" runat="server" />
<br>
<asp:label id="lblMessage" runat="server" />
</div>
</form>
<hr size=1 width=90%>
<!-- #include virtual="~/shared/viewsrc.inc" -->
</body>
</html>
Re: validation in asp.net
I have no idea which of you two I should respond to. :confused:
You can use a regular expression validator, with the regex
\d
to check for numbers only.