I am using RegularExpressionValidator to validate a textbox.
Now if the textbox is valid,i need to display a "Page is Valid" message on Label Control.
Do I do it in Code Behind or do i declare the label in javascript itself?
In javascript I have tried using the :
document.getElementById("LabelId").innerText="Your Text Here"
but it shows Microsoft JScript runtime error:
Unable to set value of the property 'innerText': object is null or undefined".
Also I have tried using innerHTML instead,but it shows the similar error. So whats the correct way to assign value to label? Edited: Below is my aspx coding:
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true"
CodeBehind="RegularExpressionValidator.aspx.cs" Inherits="ValidationTask.WebForm3" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<asp:Label ID="LabelText" runat="server" Text="Label"></asp:Label><br />
<script type="text/javascript" language="javascript">
function ValidatePage() {
debugger;
if (Page_IsValid) {
document.getElementById('<%= LabelText.ClientID %>').innerHTML = 'Page Is Valid';
}
else {
document.getElementById('<%= LabelText.ClientID %>').innerHTML = 'Page is Invalid';
}
}
</script>
<asp:Label ID="LabelZip" runat="server" Text="Enter Zip Code"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br />
<asp:Button ID="Button1" runat="server" Text="Enter" OnClientClick="return ValidatePage()" />
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" ControlToValidate="TextBox1"
ValidationExpression="\d{5}" runat="server" ErrorMessage="The zip code must be 5 numeric
digits"></asp:RegularExpressionValidator>
</asp:Content>
Thanks in Advance.
P.S. I am new here and this is my first question. Please ignore if i have made any mistakes.