I was reading an article to disable validators in Javascript using below mentioned reference
http://geekswithblogs.net/jonasb/archive/2006/08/11/87708.aspx
My practice page
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default4.aspx.cs" Inherits="Default4" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script language="javascript" type="text/javascript">
function RegexTester(ID) {
debugger;
var ID1 = document.getElementById('req');
// ValidatorEnable(
return false;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:RegularExpressionValidator ID="req" runat="server" ErrorMessage="hi" ControlToValidate="TextBox1"
ValidationExpression="^[0-9]{7,20}$" EnableClientScript="false">
</asp:RegularExpressionValidator>
<asp:TextBox ID="TextBox1" runat="server" CausesValidation="false"></asp:TextBox>
<asp:CheckBox ID="btn" runat="server" Text="Regex Tester" CausesValidation="false"
AutoPostBack="true" />
</div>
</form>
</body>
</html>
Query
In the javascript function, I am unable to get the memory for required field validator control. I mean ID1 is showing null value…Why?
Because your validator is a server side control ASP.NET will create an unique client id for it based on control’s id and its location in markup.
To get a client side id of your validator you should use:
Also there is a way to map all server side controls in a neat way:
http://jagregory.com/writings/how-to-use-clientids-in-javascript-without-the-ugliness/
If you are developing for ASP.NET 4.0 you can use ClientIDMode=”Predictable” to have better control over how ids are generated.
More info at:
http://weblogs.asp.net/asptest/archive/2009/01/06/asp-net-4-0-clientid-overview.aspx