Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1087843
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T22:59:31+00:00 2026-05-16T22:59:31+00:00

I am using javascript for customValidator to validate textboxes in ASP.Net. The code works

  • 0

I am using javascript for customValidator to validate textboxes in ASP.Net.
The code works perfectly when I am using a normal page, but as soon as I put that inside a MasterPage, the code doesn’t work.

Below is the code for my aspx page. If I put this code inside a MasterPage it doesn’t work.
Could you guys advise me how to make this work inside a MasterPage

Thanks,
Abhi.

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">

<script type="text/javascript">
 function validateOrFields(source, args){
 var sUser = document.getElementById('TextBox1');

   if (sUser.value == "")
   {
      args.IsValid = false;
   }
   else
   {
      args.IsValid = true;
   }  
   return;  
 }

<div>
    <asp:TextBox ID="TextBox1"
        runat="server"></asp:TextBox>
        <asp:CustomValidator ID="FieldValidator" 
                    runat="server" 
                    Text="Enter either a user name" 
                    ClientValidationFunction="validateOrFields" onservervalidate="FieldValidator_ServerValidate"/>
        <asp:Button ID="Button1" runat="server" Text="Button" />
</div>
</form>
</body>
</html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T22:59:32+00:00Added an answer on May 16, 2026 at 10:59 pm

    you need to get the id by using ClientID

    Replace your code by

    var sUser = document.getElementById('<%= TextBox1.ClientID %>');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been using Javascript's Date for a project, but noticed today that my code
I need to edit (using javascript) an SVG document embedded in an html page.
I've been using javascript for a while, but have never learned the language past
I am wondering what the prefered method of validating user input in asp.net using
Using JavaScript, how do I NOT detect 0, but otherwise detect null or empty
I'm using JavaScript/Jquery to make a page auto-update with a value from a database,
Without using Javascript, is there a way to make a CSS property toggle on
I'm using JavaScript to hide an image and show some text thats hidden under
I am using JavaScript and jQuery. My main file has My.js and Ajax. My.js
Ive no problems using Javascript to read the rows of a telerik radgrid component

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.