Click here to Skip to main content
15,896,606 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello everyone ,
I am working on a project where there are 3 login pages for different user for that the parameter userID and Password remains the same . For all the 3 separate login pages i need to write validation for each page so i taught of writing a JavaScript file to validate commonly where the text box ID's remains same in all the 3 login pages .

so i took a "WebFormOne.js" file into my project solution and as usual I took Jquery.js to my project

then i gave ref of Jquery.js to "WebFormOne.js"like this
JavaScript
/// <reference path="Jquery.js" />


I am getting all the jquery functions in WebFormOne.js so its not a problem to me

now coming to actual problem

in aspx page i have taken 2 textbooks like this
ASP.NET
<asp:TextBox ID="txtuserID" runat="server"></asp:TextBox><br/>
 <asp:TextBox ID="txtpassword" runat="server" TextMode="Password"></asp:TextBox><br/>
<asp:Button ID="Button1" runat="server" Text="Login"  
                        OnClientClick="return validateLoginTextBox();" onclick="Button1_Click"/>


where "validateLoginTextBox() " is a method written inside then WebFormOne.js
the code is as follows

JavaScript
/// <reference path="Jquery.js" />

function validateLoginTextBox() {
    var validationResult = true;
    var ControlContent = '';
  alert('hi');

ControlContent = $('#<%=txtuserID.ClientID %>').val();

if (ControlContent.length == 0) {
        alert('User ID Required');
       validationResult = false;
   }
ControlContent = $('#<%=txtpassword.ClientID %>').val();
if (ControlContent.length == 0) {
        alert('Password Required');
       validationResult = false;
     }
return validationResult;

}



I am getting the alert message "HI" after that it s showing '$' is undefined
Can anybody tell how can i solve this problem .


Thanks in advance

Arun
Posted

1 solution

Your code is working fine in my pc. Just one thing you can check the jquery file reference code, where you add that code. You did not show where the reference code you add. You need to add reference to your master page then from all pages you can access jquery api's.
ASP.NET
<head runat="server">
    <script type="text/javascript" src="Scripts/jquery-1.7.1.js"></script>
    <script type="text/javascript" src="Scripts/WebFormOne.js"></script>
</head>


This jquery file need to reference before your WebFormOne.js file reference. You can take jquery reference from master page and WebFormOne.js reference from your Content page where you need the javascript functions.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900